sbilharz / formwandler

Dynamic form objects for rails
MIT License
0 stars 1 forks source link

Readonly flag for fields #13

Closed sbilharz closed 6 years ago

sbilharz commented 6 years ago

It seems the current hidden and disabled flags are not enough. When a field is disabled, we don't permit its value with the submitted parameters. Suppose a use case where a field's value shall be visible but not editable to the user while being pipelined when submitting. With the current means, this is not possible. That's why I want to introduce a third flag to mark how to render a field in the view (looking at #10): readonly.

When generating your HTML with rails, you can forward this property to the view helper:

<%= f.text_field :field_name, disabled: @my_form.field(:field_name).disabled?, readonly: @my_form.field(:field_name).readonly? %>

To the user, both options will probably look the same. The difference is only in whether the parameter will be permitted in the submit request or not.