formtools/module-custom_fields

custom function

Opened this issue · 1 comments

Hi. From the documentation it's unclear how this works. I need to create a custom field based on textbox, with only numbers, but for floating point numbers (using "." as separator). How do I do it? THX!

Answering myself:

As stated in another issue, on the custom function name you just point to the function, on Display -->Javascript you write the code.

Name would be "cf_float.check_float"

And code:

var cf_float = {};
cf_float.check_float = function() {
var errors = [];
for (var i=0; i<rsv_custom_func_errors.length; i++) {
if (rsv_custom_func_errors[i].func != 'cf_float.check_float') {
continue;
}
var field_name = rsv_custom_func_errors[i].field;
var fields = $('input[name="'+ field_name + '"]');
var field_value = fields.val();
var objRegex = /(^-?\d\d*.\d\d*$)|(^-?.\d\d*$)/;
if(isNaN(parseFloat(field_value)) && !isFinite(field_value)) {
var el = document.edit_submission_form[field_name];
errors.push([el, rsv_custom_func_errors[i].err]);
}
}
if (errors.length) {
return errors;
}
return true;
}