5

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" />
2
  • Use custom javascript for this. Commented Jan 12, 2017 at 16:47
  • 1
    Any url reference for that ? Commented Jan 12, 2017 at 16:48

2 Answers 2

9

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" />
2
  • 1
    Why would this answer get a -1? This answer is perfectly fine! Commented Nov 13, 2017 at 8:11
  • Life saver. Thank you! Commented Aug 5, 2020 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.