I use the base in a rails application, and I am looking for a way to check the length of text fields in a form: I would like to display an error when the text field contains too many characters (but not when it is empty).
I tried using Foundation abide and creating my own named templates, as described in docs .
Here is the contents of my application.js file, including custom templates during Foundation initialization:
$(function(){ $(document) .foundation() .foundation('abide', { patterns: { short_field: /^.{,40}$/, long_field: /^.{,72}$/ } }); });
And here is my form code in the view:
<form data-abide> <div class="long-name-field"> <input type="text" pattern="long_field" placeholder="Long Field"> <small class="error">Too long.</small> </div> <div class="short-name-field"> <input type="text" pattern="short_field" placeholder="Short Field"> <small class="error">Too long.</small> </div> </form>
The problem is that when loading my form page, all the fields always display an error message, whether they are empty, filled out under their limit or exceed the limit of characters.
Anyone who has used successfully does something like this (or knows a better way that doesn't use custom templates)?
Greetings.
source share