matestack / matestack-ui-core

Component based web UIs in pure Ruby for Rails. Boost your productivity & easily create component based web UIs in pure Ruby.
https://www.matestack.io
MIT License
545 stars 47 forks source link

[bug] `option` with placeholder not being rendered properly #573

Closed aaron-contreras closed 1 year ago

aaron-contreras commented 2 years ago

What is the current behavior?

I've set a placeholder value and inspecting the form_select component, if a placeholder key is passed in the form_select options it sets value: nil, which should allow the disabled option to be displayed first, yet it doesn't

### From select source code
def render_options
  if placeholder
    #### HERE
    option value: nil, disabled: true, selected: init_value.nil?, text: placeholder
    #### HERE
  end

  select_options.to_a.each do |item|
    option item_label(item), value: item_value(item), disabled: item_disabled?(item)
  end
end
###

With the following form_select

bs_form_select key: :quality, class: 'form-select', options: [1, 2, 3], placeholder: "1-3", required: true

The value property is not being set in the rendered HTML option element

<option disabled="disabled" selected="selected">1-5</option>
Screen Shot 2021-11-26 at 6 19 21 PM Screen Shot 2021-11-26 at 6 19 27 PM

What is the expected behavior?

The rendered HTML should be

<option value="" disabled="disabled" selected="selected">1-5</option>

The issue lies in setting value: nil in the render options method showed above in the core component select.rb. It is not being rendered as a property in HTML and therefore not displaying the placeholder. Could be fixed by simply setting value: ''.

Which versions of Matestack, and which browser/OS are affected by this issue? Did this work in previous versions of Matestack?

Matestack-ui-core 2.1.0 Tested on Chrome and Safari