simple_form icon indicating copy to clipboard operation
simple_form copied to clipboard

`disabled: false` not passed down to rails tags

Open doits opened this issue 7 years ago • 1 comments

Environment

  • Ruby 2.5.3
  • Rails 5.2.1.1
  • Simple Form 4.1.0

Current behavior

The disabled option seems to be normalized before it is passed down to Rails' tag helper. You can see all options of a TextInput if you do the following:

    ActionView::Helpers::Tags::TextField.include(Module.new do
      def initialize(*args)
        pp args.last # those are the options
        super(*args)
      end
    end)

This is what happens with normal Rails' helper:

f.hidden_field :group, disabled: false

# => {:disabled=>false}

You can see :disabled => false is passed as is to the options. (I call this "disabled: false was passed down" below).

With simple form you do:

# A)
f.input_field :group, as: :hidden, disabled: false

# with 4.1.0 => `disabled: false` NOT passed down (there is no `disabled` key in `options`)
# with 4.0.1 => `disabled: false` passed down (`disabled: false` is in `options`)

# B)
f.input :group, as: :hidden, disabled: false

# with 4.1.0 => `disabled: false` NOT passed down
# with 4.0.1 => `disabled: false` NOT passed down

# C)
f.input :group, as: :hidden, input_html: { disabled: false }

# with 4.1.0 => `disabled: false` passed down
# with 4.0.1 => `disabled: false` passed down

So the behavior for input_field changed between 4.1.0 and 4.0.1 (which makes it consistent with the other calls though).

Still though it diverges from normal Rails behavior where disabled: false is passed down to the Tag helper, even if it is false.

Why do I need this particular detail at all? Because I have a library that checks whether disabled: false was passed down explicitly or not, so it knows if it can change the disabled key or if the user requested that it should not be changed.

Admittedly this did not work for the f.input case at all before, but this behavior now showed up with f.input_field after upgrading to simple form 4.1.0 and I noticed it the first time.

So the main questions are:

  • Is it OK for simple form to diverge from the standard Rails' behavior by filtering out disabled: false and to not pass it to Rails' tag helper? If no, then it should be fixed.
  • If yes, is there maybe another way to detect whether disabled: false was used, so the library quoted above can be made compatible with simple form?

doits avatar Nov 30 '18 11:11 doits

To be honest, I don't know why we don't pass the disabled: false down as Rails' tag helper does (BTW, I didn't know that 🙈). Maybe there is a special reason for that or we're just forgetting this option along the way and, if that's the case, we could pass it down to keep it consistent with Rails.

Probably we'll need to go deeper at Simple Form code to see why it's happening. @rafaelfranca, do you know/remember anything about it? if you don't, we can look for that in the code.

feliperenan avatar Dec 01 '18 02:12 feliperenan