JQuery form name check with square brackets

I have the following verification code for a text field, but the below field needs to be replaced with the name of the text field that is being created dynamically.

My problem is that it has a square bracket in the name - options[483998]

How can I add this to the code below, since it is obvious that if I do a direct field replacement with options[483998] , it creates the wrong encoding.

 jQuery("#product_addtocart_form").validate({ rules: { field: { required: true, range: [100, 2540] } } }); 
+6
source share
4 answers

Demo - http://jsfiddle.net/sY82j/

 jQuery("#product_addtocart_form").validate({ rules: { "options[483998]": { required: true, range: [100, 2540] } } }); 
+11
source

Can't you take it off?

 jQuery("#product_addtocart_form").validate({ rules: { 'options[483998]': { required: true, range: [100, 2540] } } }); 
0
source

Just put it in quotation marks: "options[483998]"

0
source

I tried this too, but my API verification code does not work with this technique.

 "upload_images[]": { required: true, accept:"jpg,png,jpeg" } 

I work with inputting images with multiple images, I need to check if anything was selected before submitting the form. Other inputs work fine with API validation.

0
source

Source: https://habr.com/ru/post/900681/


All Articles