3

I want a validation on same name array dynamic input textbox.Because Magento data-validate="{required:true}" is not work on same name so how to validate same name array input validation.I have following html data.How to validate same name in magento 2 ?

<input type="text" name="qty[]" class="input-text" />
<input type="text" name="qty[]" class="input-text" />
<input type="text" name="qty[]" class="input-text" />
  • Use custom javascript for this. – BornCoder Jan 12 '17 at 16:47
  • Any url reference for that ? – Niraj Patel Jan 12 '17 at 16:48
8

To validate name array dynamic input text boxes , You need to mention array input field's index like following.

<input type="text" name="qty[0]" class="input-text" />
<input type="text" name="qty[1]" class="input-text" />
<input type="text" name="qty[2]" class="input-text" />
| improve this answer | |
  • 1
    Why would this answer get a -1? This answer is perfectly fine! – Giel Berkers Nov 13 '17 at 8:11
  • Life saver. Thank you! – Marek Mularczyk Aug 5 at 5:59
0

Suggestion by @BornCoder is to create new validation for that.

Good solution is to check if one validation method can handle that situation: http://inchoo.net/magento-2/validate-custom-form-in-magento-2/ I prefer to start by use: validate-grouped-qty (because of name of input provided in example but this is only to start search)

Full solution: There is only some location, where validation rules exist out of box: SHOP/vendor/magento/magento2-base/lib/web/mage/validation.js SHOP/vendor/magento/magento2-base/lib/web/mage/validation/validation.js And of course , provided by jQuery. Check it or write custom. No more ways to accomplish task in frontend by using native solution.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.