nova-flexible-content icon indicating copy to clipboard operation
nova-flexible-content copied to clipboard

Default Values Don't Apply

Open devotoare opened this issue 4 years ago • 5 comments

Number::make('Weight')->min(0)->max(10)->step(0.01)
                        ->default(1)
                        ->rules('required'),

Results in a number field that has no value pre-entered.

Text::make('Type')
                        ->default('input')
                        ->rules('required'),

Results in a text field that has no value pre-entered.

devotoare avatar Dec 02 '20 22:12 devotoare

I have the same bug

yarbala avatar Dec 04 '20 16:12 yarbala

Workaround:

->withMeta([
     'value' => $this->weight ?? 1,
]);
Number::make('Weight')->min(0)->max(10)->step(0.01)
    ->withMeta([
        'value' => $this->weight ?? 1,
    ])
    ->rules('required')

ahinkle avatar Apr 12 '21 15:04 ahinkle

@ahinkle your workaround is not working because $this->weight is undefined inside a Flexible layout

ghost avatar Apr 17 '21 07:04 ghost

Any update instead of withMeta?

kayacekovic avatar Dec 22 '22 12:12 kayacekovic

Any update instead of withMeta?

https://github.com/whitecube/nova-flexible-content/pull/423

kayacekovic avatar Dec 22 '22 14:12 kayacekovic