With help from Jason Smith, I have some great code that will alert employees when they attempt to request leave dates that are not in the same pay period (the Pay Period Date is populated via a lookup). I added code to make the Pay Period Date field read only (wouldn't work using the Forms read only option) and hide the calendar icon:
$(document).ready(function(){ // Not equal validator window.Parsley.addValidator('notequalto', { validateString: function(value) { // return whether or not the value is the same as the first row return value == $('.PPEdate input:eq(0)').val(); }, messages: { en: 'Leave dates must be in the same pay period. Submit additional forms as needed.', } }); // assign validator when new rows are added $('.PPEtable .cf-table-add-row').click(function(){ registerValidator(); }); // register validator on existing rows registerValidator(); }); function registerValidator(){ // assign validator $('.PPEdate input').attr('data-parsley-notequalto',''); } $(document).ready(function () { $('.PPEdate input').attr('readonly',true); $('.cf-table-add-row').click(function () { $('.PPEdate input').attr('readonly',true); $('.PPEdate img').hide(); $('.PPEdate .ui-datepicker-trigger').hide(); }); });
Two things that I would like to fix/change:
When a date is selected in the Date of Leave field, the calendar picker pops up in the Pay Period Date field (even though it is read only). I have tried to disable it in both JS and CSS but neither works. Any other ideas?
Is there a way to make the Hours field read only (i.e., making it uneditable) if the alert message is present in the Pay Period Date field in the same row? My thought is that if that could happen, then the form could not be submitted, since it is a required field, until the row is corrected. I know that I could try to hide the Submit button, but it is already being manipulated in another way and I don't want to mess with that.
Thank you.