0

I'm having a set of inputs where I can add or remove them in any number > 1. I need always one and any of this field to be required. But I don't know how to achieve this in the most effective way. For now my first field is required and when I add the copy of it to the list I just removed the required attribute:

var newInput = $(previousInput)
               .clone(true)
               .attr('id', '--id_' + cloneCount)
               .removeAttr('required');
newInput.appendTo($(div));

but each of these fields may be removed by corresponding remove_button. So when the input with required attribute there will be none left. What's more then every time the same field would have to be filled in while I would like to any if these be enough. What is the proper way to achieve this?

Malvinka
  • 1,185
  • 1
  • 15
  • 36
  • 1
    You can check on submission for the input to be there instead of using require attribute – Lelio Faieta Jun 01 '20 at 16:00
  • I'm using parsley validation. Could you give me a hint how to do that? – Malvinka Jun 01 '20 at 16:01
  • If you're asking for a way to do something in a specific library, be sure to tag your question with the tag for that library. Also, this seems to be a very similar (if a little old) question: https://stackoverflow.com/questions/30526654/parsley-validator-at-least-one-field-is-required – DBS Jun 01 '20 at 16:04

0 Answers0