OwenMelbz / nova-radio-field

Provides a radio field for laravel nova with ability to toggle field visibility.
34 stars 31 forks source link

->required() and ->rules('required') does not seem to work #10

Closed vayurobins closed 4 years ago

vayurobins commented 4 years ago

Hi. Thanks for this package. I have tried to add ->rules('required') and ->required() but neither seem to have any effect. I was able to make a custom check though like this:

RadioButton::make(__('Select a Subscription'), 'plan')
    ->rules('required', function($attribute, $value, $fail) {
        if ($value == 'undefined') {
            return $fail(__('Please select a plan, this is required!'));
        }
    })
OwenMelbz commented 4 years ago

Hi,

Have you looked at what the value that gets posted is when nothing is selected?

(I’ve not used nova in over a year so I can’t really quickly check this)

If your able to submit a PR, I can merge and release

vayurobins commented 4 years ago

Hi. Yes this: $value == 'undefined'

OwenMelbz commented 4 years ago

Have you tried setting a default value?

vayurobins commented 4 years ago

No, but I don't think there should be one though. I want the user to think about the choice and select :-)

OwenMelbz commented 4 years ago

as in have you tried setting the default to something else e.g null

vayurobins commented 4 years ago

Ok, I have now tested setting

->default(null)
->required()

That did not give any message feedback to the user, it just throws an error. So same error as before

JoshMoreno commented 4 years ago

I've submitted a PR #13 , but as a temporary workaround you can use the required validation rule, but you must pass an empty string as the default value.

RadioButton::make()
    ->default('')
    ->rules('required')
    // ...