Hi folks,
I'm attempting to check if a user's Approval Limit is NOT above the value of the invoice being processed.
The aim is that, if like in the image above the limit is lower than the invoice value it'll warn and say that it needs to go to someone with a higher limit.
For this I've taken some Javascript from another thread (perhaps where I've gone wrong) and rewritten it to try and suit my purposes:
(CSS classes iValue and aLimit are added to the appropriate fields)
$(document).change(function () { // custom validator for name confirmation window.Parsley.addValidator('samevalue', { validateString: function(value, requirement, field) { var iValue = $('.IValue input').val(); var aLimit = $('.ALimit input').val(); return (iValue <= aLimit || iValue == '' || aLimit == ''); }, messages: { en: 'Approver Limit Cannot Be Smaller Than The Invoice Value!.', } }); // assign validator to name fields $('.IValue input, .ALimit input').attr('data-parsley-samevalue',''); });
The original thread was here btw.
I should explain the issue I'm having in greater detail.
Firstly I'm using lookups (stored procedures) to populate the 'Approver Name' and 'Approval Limit' fields so that only the correct people for that 'Team' appear. (Team is basically the approval tier £1000-£15000)
This means that the validation doesn't actually proc unless you manually go and type in the limit or retype the 'Gross Value' (which is also a lookup).
My aim is for as little manual intervention as possible so I'm hoping to not have to have the users mess with either of the fields being compared by the code.
Also another strange issue I've notices is if the 'Gross Value' is 9999 (which it is in one of my example invoices) then only an 'Approval Limit' starting with 9999 will validate which confuses me greatly...
Apologies for the house of cards and hot mess but any advice would be greatly appreciated