Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsley JS 2.x - how do you validate hidden fields?

I would like to validate hidden fields, so essentially I want to remove input[type=hidden] from parsley's list of excluded form elements. I've tried explicitly setting excluded elements in parsley's options, but hidden fields are still not validated. E.g:

$(element).parsley({
    excluded: 'input[type=button], input[type=submit]'
});

Any thoughts on how to accomplish this, or what I'm doing wrong?

like image 236
kitsimons Avatar asked Oct 29 '25 05:10

kitsimons


2 Answers

I'm guessing this is a bug.

Take this form:

<form method="post" id="myForm">
    <input type="text" name="field1" value="" class="required" />
    <input type="hidden" name="hiddeninput" value="" class="required" />
    <input type="submit" value="Go">
</form>

With the following javascript, even though we tell Parsley to validate hidden fields, it does not work:

$("#myForm").parsley({
    excluded: 'input[type=button], input[type=submit], input[type=reset]',
    inputs: 'input, textarea, select, input[type=hidden], :hidden',
});

However, if you define this as a global configuration, it does work

window.ParsleyConfig = {
    excluded: 'input[type=button], input[type=submit], input[type=reset]',
    inputs: 'input, textarea, select, input[type=hidden], :hidden',
};

$("#myForm").parsley();
like image 187
Luís Cruz Avatar answered Oct 30 '25 21:10

Luís Cruz


what i did was: make input field readonly and hide via css.

like image 23
bnomei Avatar answered Oct 30 '25 23:10

bnomei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!