I am new to ROR. I just want to know is it possible to disable a submit tag button if the text_field is empty.??
thanks
You can do it with jquery like this,
Live Demo
if($('#text_field').val() ==  "") 
   $('#submitButtonId').attr('disabled', true);
$('#text_field').keyup(function(){
    if($('#text_field').val() !=  "") 
         $('#submitButtonId').attr('disabled', false);    
    else
         $('#submitButtonId').attr('disabled', true);   
});
For latest version of jQuery you may need to use prop() instead of attr() to set the disabled property of the element.
if($('#text_field').val() ==  "") 
   $('#submitButtonId').prop('disabled', true);
                        Typically it's done through validations, so the button stays active but the form gets validation errors and doesn't save. In your model you would add:
validates_presence_of :some_field, :some_other_field
If you want to do it anyway, you would use javascript to accomplish it.
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