Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom function #11

Open
geprieto opened this issue Jun 15, 2020 · 1 comment
Open

custom function #11

geprieto opened this issue Jun 15, 2020 · 1 comment

Comments

@geprieto
Copy link

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!

@geprieto
Copy link
Author

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant