Closed phuclh closed 3 years ago
@phuclh No, but this is how you can achieve at this moment:
Text::make('Some Setting', 'key')->withMeta([
'value' => nova_get_setting('key', 'Default Value')
])
There's one issue with that. What if there's a field that has a default value but the user wants it to be null (or empty). They would have to empty the field every time, since it would get prefilled with the default value.
Actually, nevermind, the ->default()
would never work properly, I don't think. As the serialization function in Nova does the following:
'value' => $this->resolveDefaultValue($request) ?? $this->value,
If I emulated a 'create' request so resolveDefaultValue
would actually resolve the default value, it would overwrite the actual value each time.
However, what I could do is create a 'defaultSetting' macro that does the same thing as @Landish's code. So you could call ->defaultSetting('bleh')
on any field. Would that be close enough?
Is there any ways to use the
default
method on this package? Now it just leaves a blank input. Thank you!