laravel-form-components icon indicating copy to clipboard operation
laravel-form-components copied to clipboard

ErrorBag Definition

Open chellmann opened this issue 5 years ago • 4 comments

Hello,

thank you very much for your work and willing to share it.

Is it possible to set the ErrorBag in the x-form element? It would be useful when displaying more than one form on a single page.

Thanks

chellmann avatar Oct 07 '20 19:10 chellmann

Do you mean something like this?

<x-form error-bag="login">
    {{--  --}}
</x-form>

<x-form error-bag="register">
    {{--  --}}
</x-form>

pascalbaljet avatar Oct 13 '20 07:10 pascalbaljet

Yes, exactly this.

chellmann avatar Oct 13 '20 07:10 chellmann

With the recent support for error bag should be fixed also for single input hasError() like here:

https://github.com/protonemedia/laravel-form-components/blob/master/resources/views/bootstrap-4/form-input.blade.php#L13

The check must be:

@error('field', 'errorBagName') is-invalid @enderror

Setting error bag on form level would be better to avoid to pass bag name to each component

thewebartisan7 avatar Oct 22 '20 07:10 thewebartisan7

I added that in preparation for solving this issue :)

A Blade Component can't access their parent's data because the compiler renders the children/slots before the parent. Marcel is working on a PR to support this. Whenever that gets merged, we'll be able to do bindings and setting the bag on the x-form element:

<x-form error-bag="profile" :bind="$user">
    <x-form-input name="biography" />
</x-form>

I'll leave this issue open until then.

pascalbaljet avatar Oct 22 '20 07:10 pascalbaljet