Reputation: 3300
I am most of the time stuck building web applications or SMBs. But I have my days working on front ends. One interesting JS library I recently met is Parsley.js
for web form validity check. Really cool.
In a new project I am working, I decided to use Parsley, and am not sure how to do this.
I got a select box with two options, Yes
, No
. If Yes
is selected, I need to show the user a text-box that is required.
I went through Parsley
documentation nearly twice, but couldn't figure out a way. But I think this kind of forms are common and should be supported by Parsley.
Is it possible through Parsley.js
? Would appreciate your advice.
Upvotes: 0
Views: 1698
Reputation: 1482
If you are having trouble with this like I did, see what guillaumpotier posted. Destroy parsley, modify the inputs, then initialize parsley again; here is his code:
// destroy
$('#myForm').parsley('destroy');
// change attribute
$('#myTestField').data('minlength', 2);
// assign parsley to do the job
$('#myForm').parsley();
Upvotes: 0
Reputation: 514
it can be done , just need to check your select box selected value, if is 'Yes' then add
$( '#field' ).parsley( 'addConstraint', { required: true } );
if the value is 'No'
$( '#field' ).parsley( 'removeConstraint', 'required' );
Upvotes: 2