I'm trying to figure out if/how I can use the parsley validator to compare fields in a table and alert if subsequent entries DO NOT match the first entry.
In our leave request process, we need for leave request dates to all be in the same pay period. Request dates (Date of Leave) are entered in a table, and the pay period dates (PPE) are populated from a lookup. As rows are added (up to five) I'd like to find a way to alert users when additional dates entered in the table do not match the PPE of the first entry.
I've found posts here and here that use the parsley validator to look for and alert when there is a duplicate, but that's the opposite of what I want.
Here is what I have so far:
$(document).ready(function(){
register();
$('.RequestTypeDetails').click(register);
window.Parsley.addValidator('notequalto', {
validateString: function(value) {
var valueLookup = $('.PPEdate input').map(function() {return $(this).val(); }).get();
return _.filter(valueLookup, function(v) { return v !== value }).length == 1;
},
messages: {
en: 'Leave dates must be in the same pay period!',
}
});
function register()
{
$('.PPEdate input').attr('data-parsley-notequalto', '');
$('.PPEdate input').change(function(){
$('.PPEdate input').each(function(index, el){$(el).parsley().validate();})
});
}
});
I'd be most grateful for any assistance. Thank you.