I have a table (named invoiceInformationTable) with single line field (named bpNumber) the user can type whatever they wish in it. Then based on this value I used a lookup to fill a hidden field (named bpTestField). What I want to be able to do is create a custom error on the single line field (bpNumber) that is trigged when the hidden field (bpTestField) is empty. I have tried to make a custom parsley error, but so far have been unable to get it working.
The reason I’m not using a drop down and forcing the user to pick valid values, is because the look up is too large and my form will freeze.
I'm including my code, but it's mostly just alerts testing to see if I'm getting the correct values to check.
validateBPNumber() is not even close.. it just need to check if empty or not. Currently it always sends back true.
/*******************************************************************************/ /* START: initial Set up custom error message and checking for moved fields */ /*******************************************************************************/ function validateBPNumber(thefield) { // alert('got here validateBPNumber'); //alert('got here field: '+ thefield.val() ); // if(value > 10 && value < 100) // { return true; // } // else // { // return false; // }; }; function addValidator () { $('.bpNumber input').each(function() { //alert('found one'); var attr = $(this).attr('data-parsley-bpnumbervalid'); if (typeof attr == typeof undefined || attr == false) { $(this).attr('data-parsley-bpnumbervalid',''); }; }); }; /*******************************************************************************/ /* END: initial Set up custom error message and checking for moved fields */ /*******************************************************************************/ $(document).ready (function () { /*******************************************************************************/ /* START: final Set up custom error message and checking for moved fields */ /*******************************************************************************/ window.Parsley.addValidator('bpnumbervalid', { validateString: function(value, requirement, field) { // validateString: function(value) { // alert('the $(field) ' + $(field).val ); var bpNum = $('.bpNumber input').val(); var bpDesc = $('.bpTestField input').val(); var test = field.$element.siblings('.bpTestField'); alert('test ' + test.val()); return validateBPNumber(bpDesc); // return validateBPNumber($(field)); }, messages: { en: 'Needs to be a valid BP Number' } }); addValidator(); $(document).on('click','.cf-table-add-row',function() { addValidator(); }); /* force validation on blur event */ $('.bpTestField').change(function(){ $('.bpNumber input').parsley().validate(); }); /*******************************************************************************/ /* END: final Set up custom error message and checking for moved fields */ /*******************************************************************************/ });