yassilah / laravel-nova-nested-form

This package allows you to include your nested relationships' forms into a parent form.
240 stars 96 forks source link

Validation messages are not displayed #104

Open iBet7o opened 4 years ago

iBet7o commented 4 years ago

I have configured NestedForm in a field, but creating a record with missing mandatory fields does not show me the errors in each field.

I show you how I have everything configured.

Models

...

class Order extends Model
{
    ...

    public function notifications()
    {
        return $this->hasMany(\App\OrderNotification::class);
    }

    ...
}
...

class OrderNotification extends Model
{
    ...

    public function order()
    {
        return $this->belongsTo(\App\Order::class);
    }

    ...
}

Nova Resources

...

class Order extends Resource
{
    ...

    public function fields(Request $request)
    {
        $nestedOrderNotifications = NestedForm::make(__('Notifications'), 'notifications', OrderNotification::class);
        $nestedOrderNotifications
            ->max(1)
            ->heading('')
            ->hideWhenUpdating();

        return [
            $this->buildIndexFields(),

            $this->buildFormFields(),

            $this->buildDetailFields(),

            $nestedOrderNotifications,
        ];
    }

    ...
}
...

class OrderNotification extends Resource
{
    ...

    public function fields(Request $request)
    {
        return [
            BelongsTo::make(__('Order'), 'order', Order::class)
                ->exceptOnForms(),

            Text::make(__('Subject'), 'subject')
                ->rules('required', 'string'),

            Textarea::make(__('Message'), 'message')
                ->rules('required', 'string')
                ->alwaysShow()
                ->hideFromIndex(),

            ...
        ];
    }

    ...
}

In the browser

image

Only the global toasted notification appears, but not in the failed fields.

GautierDele commented 4 years ago

Having the same issue here, anything new on your side ?

lopandpe commented 3 years ago

Same here...

Casperhr commented 3 years ago

Same here

aswin-ghosh-chenattil commented 3 years ago

Same here

MarDenDev commented 2 years ago

Same problem here.

Maybe that's happening because the name of the fields aren't the same in the main form and in the subform? For example, let's suppose I have a resource users that has a required field named first_name. In the main resource form the input attribute name will be first_name, but in an hypothetic subform it will be users[0][first_name].

I'm definately not a Vue expert so I'm only assuming.