Select form field with default() does not give expected value when model $attributes is set #6573
Replies: 2 comments
-
Model will always have the higher priority over default. Moving this to Idea and Feature Request. |
Beta Was this translation helpful? Give feedback.
-
class SomeModel extends Model {
protected $attributes = [
'reason' => 'c',
];
}
Select::make('Reason', 'reason')
->options([
'a' => 'A`,
'b' => 'B',
])
->default('a'),
Select::make('Reason 2', 'reason')
->options([
'a' => 'A`,
'b' => 'B',
])
->default('b'), Why would a developer expect the provided defaults to be ignored? Nova documentation states:
There's no mention that it might be overridden by the model or anything else. When writing the above code, explicitly specifying the default for specific field instances, one would expect the field to default to that value. In this case, both fields would just ignore the provided default value because the model states otherwise and one would have no idea why. Furthermore, let's say I add the Wouldn't it be a bit more logical to use whatever is explicitly provided and default to what model states in case no explicit default is provided? |
Beta Was this translation helpful? Give feedback.
-
Description:
I have a field like:
The default expected value would be "Supplier" select in the field. However, I see "Our platform", because:
In the model we have:
I would think that
default()
in Nova context should override the default value of Laravel context.In my opinion it is a bug or at least not expected behaviour.
Now we need to use something like
->withMeta(['value' => 'supplier'])
to get arround this behaviour.Detailed steps to reproduce the issue on a fresh Nova installation:
An example given above, resource with a single field and a model with $attributes.
Beta Was this translation helpful? Give feedback.
All reactions