I hope in the next version of Forms (currently on 10.2.1) that there is a way to set the minimum or range value on a currency field. Currently we can set it to required but if I need it also to be greater than $0.00 or within a range, it's not an option. I understand I can use javascript to accomplish this but in a table (like an expense report), that coding can be tedious (especially for non-coding customers) for something that is available in the number field. Has anyone found an easy way to verify a currency value is greater than 0.00 outside of assigning classes to each currency field and adding JS to verify it every time they change it?
Discussion
Discussion
replied on October 11, 2017
Hey mate,
You didn't mention what version of forms you are using so ive written this assuming 10.2. If you have anything before that let me know cause ill need to use different code. But this should do what you are after. :)
function validateCur(value) { if(parseFloat(value.replace('$','')) >= 0.00) { return true; } else { return false; } } function addValidator () { $('.currency').each(function() { var attr = $(this).attr('data-parsley-cur'); if (typeof attr == typeof undefined || attr == false) { $(this).attr('data-parsley-cur',''); } }); } $(document).ready(function() { window.Parsley.addValidator('cur', { validateString: function(value) { return validateCur(value); }, messages: { en: 'Currency must be greater then $0.00' } }); addValidator(); $(document).on('click','.cf-table-add-row',function() { addValidator(); }); });
2
0
replied on October 11, 2017
This one has support for rows added via lookup.
function validateCur(value) { if(parseFloat(value.replace('$','')) >= 0.00) { return true; } else { return false; } } function addValidator () { $('.currency').each(function() { var attr = $(this).attr('data-parsley-cur'); if (typeof attr == typeof undefined || attr == false) { $(this).attr('data-parsley-cur',''); } }); } $(document).ready(function() { window.Parsley.addValidator('cur', { validateString: function(value) { return validateCur(value); }, messages: { en: 'Currency must be greater then $0.00' } }); addValidator(); $(document).on('click','.cf-table-add-row',function() { addValidator(); }); $(document).on('lookupcomplete', function(event){ addValidator(); }); });
2
0
You are not allowed to follow up in this post.