Reputation: 5323
validation is not working with the following custom validation (all other standard validation html attributes are working). I have removed inputs in the form that are not applicable.
<form id="regForm" role="form" method="post" action="" accept-charset="UTF-8">
<div class="form-group">
<label for="wards">Your Ward</label>
<select name="fields[ward]" class="form-control">
<option value="" selected="selected">SELECT WARD</option>
<option value="item">item 1</option>
</select>
<p class="help-block">It is important that you select the ward your current membership records reside in!</p>
</div>
<div class="form-group">
<label for="wardOther">Other Ward or Not in Australia?</label>
<textarea class="form-control" id="wardOther" name="fields[wardOther]" rows="4" data-parsley-conditionalrequired='[name=\"fields[ward]\"] option:selected' data-parsley-validate-if-empty data-parsley-success-class="" data-parsley-conditionalrequired-message="This value is required since you did not select an australian ward!"></textarea>
<p class="help-block">Please tell us the Country, Stake, Ward, and Bishops Name you are attending from</p>
</div>
<script>
$(document).ready(function() {
$('#regForm').parsley({
validators: {
conditionalrequired: {
fn: function (value, requirements) {
console.log('fdsafds');
if ($(requirements).val() == '' && '' == value)
return false;
return true;
},
priority: 32
}
}
});
});
</script>
The console.log is not triggering.
Upvotes: 0
Views: 3310
Reputation: 1160
The customer validator is not working at your case because you didn't specify the form name value and "data-parsley-validate" to the form definition.
<form id="regForm" role="form" method="post" action="" accept-charset="UTF-8">
Just add name="regForm" and it should work properly.
<form id="regForm" name="regForm" role="form" method="post" action="" accept-charset="UTF-8" data-parsley-validate>
Upvotes: 1
Reputation: 530
I used a bit different approach for creating custom validator. You can see the working example here http://jsfiddle.net/Hmhjy/
window.ParsleyValidator.addValidator('conditionalrequired',
function (value, requirement) {
console.log('fdsafds');
if ($(requirements).val() == '' && '' == value) {
return false;
}
return false;
}, 32)
.addMessage('en', 'conditionalrequired', 'This value is required since you did not select an australian ward!');
$('#regForm').parsley();
Upvotes: 0