I have a form that submits with data-remote => true.
The form has one field, a textarea. I want to prevent submission of the form if the textarea length is 0 and only allow a form submission if the length is GT 1.
How do I bind to the form in a rails 3, jquery ujs friendly way. I tried the following but that did not stop the form submissions:
$('#new_feedback').bind('ajax:before', function() {
e.preventDefault();
} );
Thanks
You can bind directly to the form itself. This way, you can check the field you want as well as any other fields you may want to check when the form is submitted. return false is what cancels the form submission.
$('#myform').submit(function()
{
if($('#fieldtocheck').val().length < 1)
{
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With