Search code examples
ruby-on-railsrubyhaml

Disabled Haml field is not passed to my rb file


I have a single form which has some input fields. This form, firstly get values from database and fill them in. If they have value they will be disabled.

=text_field_tag("dt|#{a_key}",(begin;a_mock["dt_open"];rescue;nil;end), :class => "form-control",  :disabled => a_mock["active"] == "true" )

In my rb file there is a rule which validate date. If the field is blank:

if !dt_open.blank?
   ...
end

What I noticed is if the field are disabled, it doesn't send. I know because I print the message and the field aren't there. How can overcome this behavior in haml?


Solution

  • Input with disabled attribute will not submitted, you can user readonly rather disabled, did the almost same thing you can not change or edit input field value.

    Another solution

    If you still want to use the disabled attribute the you can apply the following javascript to allow submit the disabled

     <script>
         $('#your_form_id').submit(function() {
              $("#disabled_input_field_id").prop('disabled', false);
              //your code goes here
         })
     </script>