guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.04k stars 1.31k forks source link

data-required is not working while using dynamically in parsley validator #695

Closed shankumars closed 8 years ago

shankumars commented 10 years ago

Hi I am using the parsley validate plug-in to validate my form. But when I am add the attribute ' data-required="true" ' manually through jquery based on the radio button option select by client.

please any one help me or guide me right path for this problem.

thanks Kumar Shanmugam

guillaumepotier commented 10 years ago

If you are using Parsley 2.x you must use data-parsley-required.

shankumars commented 10 years ago

Hi thank you for reply.... but still it not working me.....

<label class="col-sm-4" for="particulars_to" > Create Using</label>
<div><input type="radio" name="particulars_to" id="particulars_to1" class="select" value="0" checked="checked"> <label for="particulars_to1" class="icheck_label">All</label></div>
<div><input type="radio" name="particulars_to" id="particulars_to2" class="select" value="1" > <label for="particulars_to2" class="icheck_label">Admission No</label></div>

<br>
<div id="admission" style="display:none">
<label for="admission_no" class="req">Student No</label>
<input type="text" id="admission_no" name="admission_no" class="form-control" >
</div> 
$('.select').click(function(event){
        if($(this).val() == 0){
            $('#admission').css('display', 'none');
            $('#admission_no').attr('data-required', 'false');
        }

        if($(this).val() == 1){
            $('#admission').css('display', 'block');
            $('#admission_no').attr('data-parsley-required', 'true');
        }
});

Here when I select second option radio button, the script code will trigger and the attribute also added but the validation is not working..... It was an option and attribute add through script. If you can not understand please reply me.... else give some solution.

thanks Kumar Shanmugam

MxRay commented 8 years ago

I've got the same problem. I manually add required attribute only when user selected a certain option. I'm using parsley.js with Step Form Wizard, and i need to validate manually added required before user moves to next step.

marcandre commented 8 years ago

For the scenario when there is a validation error showing and myinput is no longer required, then parsley needs to be called somehow. The best way is probably to $myinput.trigger('input'), basically faking that the user has modified that input. If there's an error showing, validation will be redone.

Closing this, please provide CodePen if there's still an issue.

MxRay commented 8 years ago

New version of parsley.js(2.3.6) did the trick. It works ok, now.