I want to validate a "true/false" requirement on grouped radio inputs using parsleyjs.
I have applied a multiple attribute data-parsley-multiple="my_input_group" so that they will validate together if required, however I am unsure how to create a custom validator to ensure the value is True and not False.
<div class="custom-control custom-radio custom-control-inline">
<input
type="radio" id="customRadioInline1" name="customRadioInline1" class="custom-control-input"
value="True" data-parsley-multiple="my_input_group">
<label class="custom-control-label" for="customRadioInline1">Yes</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input
type="radio" id="customRadioInline2" name="customRadioInline1" class="custom-control-input"
value="False" data-parsley-multiple="my_input_group">
<label class="custom-control-label" for="customRadioInline2">No</label>
</div>
I think the way to do it is using validateMultiple to pass an array to a custom validator, however there are no examples in the docs as to how I achieve this. For example, if I add data-parsley-myvalidator=true to each input and use:
window.Parsley.addValidator('myvalidator', {
requirementType: 'integer',
validateMultiple(values, requirement, instance) {
console.log('values', values);
return true;
},
messages: {
en: "'Yes' required.",
},
});
I get:
Uncaught Validator
undefinedonly handles multiple values
How do I pass an array of values to a validateMultiple custom validator?