Search code examples
ruby-on-rails-4

Rails form_tag does not send params if disabled: true


I have a form_tag in my view and a few text_field_tag nested in it. I do not want the user to edit the text fields so I did :disabled => true.

The problem: If I do :disabled => true the text field value is not passed in params hash, while if I do :readonly => true it does send the values in params hash

Is this expected? If yes then there is no mention of this in the documentation. If not, then should I file a issue in GitHub?


Solution

  • Yes, that is the expected behavior. It is probably not mentioned in the Rails documentation because the disabled and readonly control behavior is defined by the W3C spec.

    See the W3C documentation for Disabled controls, which states "disabled controls cannot be successful". A "successful" control is defined as being "'valid' for submission." Setting disabled to true on an input field in Rails will not cause it to not be submitted.

    Read-only controls, however, can be successful. Therefore, if you wanted the value to be submitted, but not editable, you should use readonly set to true.