Closed JamesPoel closed 6 years ago
You should not have anything special to do. Errors will be shown automatically when returning to the form (package checks old input and errors).
You have sample usage on my package workbench project:
Ah, I've found the issue.
The errors don't show up if you open the form in one blade file and then extend this file and include the fields using @yield/@section.
This is because, when the form is built this way, @this->formState (ln 38 of Input.php, for example), is set to null: https://github.com/marvinlabs/laravel-html-bootstrap-4/blob/master/src/Bootstrap/Elements/Input.php#L38
Which causes ln 77-78 to be falsey: https://github.com/marvinlabs/laravel-html-bootstrap-4/blob/master/src/Bootstrap/Elements/Input.php#L77
E.g.
page1.blade.php:
{{ bs()->openForm('post', '/' ) }}
@yield( 'form' )
{{ bs()->submit( 'Submit' ) }}
{{ bs()->closeForm() }}
page2.blade.php:
@extends( 'page1' )
@section( 'form' )
{{ bs()->formGroup( bs()->text( 'test' ) )->label( 'Test' ) }}
@endsection
Could this perhaps be looked into?
Hi,
Looks like in that case, closeForm is called before the section content is even inserted.
Not sure if that can be fixed as it seems to be how layouts work in Blade.
Would be happy to accept a PR if you find a fix.
Closing this for now, if you have a PR to fix that, I'd review it happily.
A rubbish workaround, but this works.
If you call bs()->openForm( ... )
in the parent view, but call bs()->closeForm()
in the child view, the validation works.
Hi This is great, but how do you show validation errors against the fields? (.is-invalid, .invalid-feedback etc?) I see references to it within the package, but I can't find any example of implementing it. Thanks