casperin / nod

Plugin that gives you frontend validation for forms.
http://casperin.github.io/nod/
381 stars 137 forks source link

How do you validate hidden input values? #91

Closed thomasjoyce closed 9 years ago

thomasjoyce commented 9 years ago

Example:

Is this possible to do?

The code below did not work. thanks for your help.

var n = nod();

// We disable the submit button if there are errors. n.configure({ submit: '.configure_blar_button', disableSubmit: true });

n.add([{ selector: '#blar_title', validate: 'min-length:2', errorMessage: 'Your name must be at least two characters long.' } ]);

casperin commented 9 years ago

http://jsfiddle.net/bygc9cc5/ Works fine for me.

thomasjoyce commented 9 years ago

oh i meant the input tag is hidden [style="display:none;" ] and i want to validate it's value base on the contenteditable div input.

Something like this:

<div class="editable_wrapper">

       <div class="form_editable"  id="title" contenteditable="true">
               abc 
       </div>
      <input id="blar_title" name="blar[title]" style="display:none;" type="text" value="abc">

</div>
casperin commented 9 years ago

Maybe you forgot to fire a change event? This works exactly as I'd expect it to: http://jsfiddle.net/bygc9cc5/2/

and http://jsfiddle.net/bygc9cc5/1/ for a version where the input field is not hidden.

thomasjoyce commented 9 years ago

Hi Casperin :-p

Thanks for the quick response ;-) Yeah, you right, i did not fire a change of event after the validation. Thanks for the guidance.