laravel / nova-issues

554 stars 35 forks source link

Select Field does not return a value on v4.32.12 (strict equality issue) #6211

Closed LTKort closed 6 months ago

LTKort commented 7 months ago

Description:

Since the update for v4.32.12, a Select field with options that uses an Integer as key is not returned as a valid selectedOption. In the SelectField.vue there are some changes made with comparisons:

let selectedOption = find(
    this.currentField.options,
-     v => v.value == this.currentField.value
+     v => v.value === this.currentField.value
)

The key type (this.currentField.value) differs from the selected options key type (v.value), which causes an empty selectedOption. It looks like the selected value is compared as text vs number, while PHP sets the value as an integer. The issue does not appear in v4.32.11

Detailed steps to reproduce the issue on a fresh Nova installation:

Add a Select field to an Action, fill the with options $options = User::limit(5)->pluck("name", "id"); (Array or Collection) Run the action, the field value for the handle with be empty.

filipposallemi commented 6 months ago

@taylorotwell @davidhemphill shame

LTKort commented 6 months ago

@crynobone If I add a function to map the option values to a string, the Select field & strict equality seems to be working.

Example:

mappedOptions() {
  let mappedOptions = this.currentField.options.map(option => {
    return { label: option.label, value: `${option.value}` }
  })
  return Object.assign(this.currentField.options, mappedOptions)
},

Before: {label: 'Lars', value: 1} After: {label: 'Lars', value: '1'}

mddickens commented 6 months ago

@taylorotwell @davidhemphill shame

Yep, blew up production this morning. Does anyone test these changes?

filipposallemi commented 6 months ago

The reality is that they are not using Nova at all otherwise they would have spot those issues immediately

VenoM9078 commented 6 months ago

been 2 days, any update on this?

github-actions[bot] commented 6 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.