cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x] Fix handling number keys in fieldtypes using HasSelectOptions

Open morhi opened this issue 1 year ago • 0 comments

Due to a change in 0b854030a495d73438ac14963eaf59c0e212dc17 the ButtonGroup fieldtype cannot display a button as active, if the key is a number. This is because the HTML button uses strings for its value, but the PHP side will cast numeric values to numbers, which then will fail the === comparison.

Also, if you change the default options for the Width fieldtype the resulting list will contain integer and string keys. It breaks the Width fieldtype to properly display the selected width, because it uses a strict comparison, too.

Since all HTML form elements like select, input, button work with strings only, I thought it makes sense, to work with string values on the JS side only, too. The Width fieldtype needs to compare numbers, so it will cast all options to a number and ignore non-numeric values, which don't really make sense in this field.

This change should not affect the augmented value of the fieldtypes, because during augmentation numeric values will be cast to an integer anyway.

This commit will

  • make the ButtonGroup fieldtype work with number keys again
  • make the Width fieldtype work again, if the default options have been changed by the user, because changing the prefilled list will result in a mix of strings and integers
  • output labels consistently as strings

Fixes #10915.

morhi avatar Oct 08 '24 12:10 morhi