I did try to add this code to "Before field" inside Customize html:
script
jQuery(function($) {
// Set the maximum length for the number field
$('#field_ID').attr('maxlength', '4');
});
script
I changed field_ID to the actual field ID of the number input, but that did nothing.
That won't work because maxlength does not work with an input field of type number. You have to set of a listener for keypress or something, count the characters and eat up anything beyond 4.
Try this https://paste2.org/pfN6DHYe , making sure to change the field id to match yours.
Hi Rob, thank you for your reply and for the code. And sorry for late response. Where do you usually type/write the code in formidable pro? Whenever i type code inside the "Before Field" or in "After Field" or anywhere in Customize html, it just doesnt want to react. How and where do you write custom js code for stuff to work with formidable?
Post a screenshot of exactly what you have in your After Fields (or Before Fields) section. Those are the locations in which to place scripts.
See above comment. A phone field is "tel" type, which isn't "number" so it works in that case.
Hi @Rob LeVine,
Here is a screenshot of what I wrote in the Before field.
I tried with both Field ID and Field Key. none of them react.
Also when I want to add other scripts like interest rate calculations it just doesnt want to react.
There is no chance your field id is 3hyc72_myrestrictednumberfield. You want the id of the field and it's definitely going to start with field_ and then append the field key as seen in your field options screen. So I'm guessing that it should be #field_3hyc72. You can also tell what the field id is by using the browser developer tools and inspecting the element. If correcting the id doesn't work, use the developer tools to show the debug console and make sure there are no jquery errors. Also, I prefer putting the jQuery code in the After Fields section.
It is field_ plus the field key. I suggest you use the developer tools (F12) to inspect the object as that will help you identify it.
"field_" plus the field key is the field's ID. The formidable ID is not relevant in this case.
Please login or Register to submit your answer