marvinlabs / laravel-html-bootstrap-4

Bootstrap 4 fluent HTML builder
MIT License
42 stars 15 forks source link

No error message under field after failed validation #22

Closed benkelukas closed 6 years ago

benkelukas commented 6 years ago

Hi, first of all, thanks for this awesom package, it is just what i was looking for.

However, I'm having a slight issue regarding validation and showing error messages. Right now, if validation fails, the fields get correct is-invalid class but i cannot see the error message from the validator (e.g. Field :field is required).

Here is my code:

<div class="row mb-3">
    <div class="col-6">
        {!! bs()->text('first_name')->placeholder(__('core::register.form.first_name')) !!}
    </div>
    <div class="col-6">
        {!! bs()->text('last_name')->placeholder(__('core::register.form.last_name')) !!}
    </div>
</div>
{!! bs()->inputGroup()->addClass('mb-3')->prefix("<span class='input-group-text'><i class='icon-user'></i></span>", false)->control(bs()->email('email')->placeholder(__('core::register.form.email'))) !!}
{!! bs()->inputGroup()->addClass('mb-3')->prefix('<span class="input-group-text"><i class="icon-lock"></i></span>', false)->control(bs()->password('password')->placeholder(__('core::register.form.password'))) !!}
 {!! bs()->inputGroup()->addClass('mb-3')->prefix('<span class="input-group-text"><i class="icon-lock"></i></span>', false)->control(bs()->password('password_confirmation')->placeholder(__('core::register.form.password_confirmation'))) !!}

And here is a screenshot after failed validation: screenshot-2018-3-13 coreui - open source bootstrap admin template

Do i need to do something more for the error messages to show up?

Thanks

vpratfr commented 6 years ago

Are you using latest package version and stable bs4 ?

benkelukas commented 6 years ago

Hi, yes the version of package is (from composer.lock)

"name": "marvinlabs/laravel-html-bootstrap-4",
"version": "v0.8.1",

version of bootstrap is (from yarn.lock)

bootstrap@4.0.0:
version "4.0.0"
vpratfr commented 6 years ago

I cannot reproduce it on my workbench. Are the messages in the html source? Or fully omitted?

Have you tried putting some breakpoints in the source code to see what was going on?

vpratfr commented 6 years ago

Here is some code that works:

        {{ bs()->formGroup()
                ->control(bs()->inputGroup()
                        ->suffix(fa()->icon('user'))
                        ->control(bs()->text('last_name', 'Doe')))
                ->label('Last name') }}

In the prefix/suffix, you don't need the wrapper span, only the icon element is required.

Sample code is there:

https://github.com/marvinlabs/laravel-workbench/blob/master/resources/views/laravel-html-bootstrap-4/form.blade.php

benkelukas commented 6 years ago

Hi, thanks a lot for Your help and sorry for the issue, I've thought that i do not need to use form group when using input group, my bad.

However i cannot use the fa() helper, i get undefined function error, i have searched for the function in repo and could not find it, so i used the wrapper span instead.

vpratfr commented 6 years ago

Oh,

I got that.

You have not wrapped the controls within form groups.

Form groups are the ones which display the error messages.

That should work:

    <div class="row mb-3">
        {!! bs()->formGroup(bs()->text('first_name')
                                ->placeholder(__('core::register.form.first_name')))
                ->addClass("col-6") !!}

        {!! bs()->formGroup(bs()->text('last_name')
                                ->placeholder(__('core::register.form.last_name')))
                ->addClass("col-6") !!}
    </div>

    {!! bs()->formGroup(bs()->inputGroup()
                            ->prefix("<i class='icon-user'></i>", false)
                            ->control(bs()->email('email')->placeholder(__('core::register.form.email'))))
            ->addClass('mb-3') !!}

    {!! bs()->formGroup(bs()->inputGroup()
                            ->addClass('mb-3')
                            ->prefix('<i class="icon-lock"></i>', false)
                            ->control(bs()->password('password')->placeholder(__('core::register.form.password'))))
            ->addClass('mb-3') !!}

    {!! bs()->formGroup(bs()->inputGroup()
                            ->addClass('mb-3')
                            ->prefix('<i class="icon-lock"></i>', false)
                            ->control(bs()->password('password_confirmation')->placeholder(__('core::register.form.password_confirmation'))))
            ->addClass('mb-3') !!}
vpratfr commented 6 years ago

The fa() function comes from another package I made in the same spirit: https://github.com/marvinlabs/laravel-html-font-awesome

benkelukas commented 6 years ago

Awesome, thanks again for quick support.

vpratfr commented 6 years ago

You're welcome. Let me know if there are missing features. Do not hesitate to submit a few pull requests if you can.

benkelukas commented 6 years ago

Well, maybe the https://github.com/marvinlabs/laravel-html-font-awesome should either be mentioned in documentation or defined as dependency in composer.json - it is used in examples, but there is not information from where the helper fa() comes from. What do you think about that?

vpratfr commented 6 years ago

Clearly it should not be added as a dependency (no need for that package to use this one).

Regarding the samples, they are located on my package workbench project (not this package project), this is why I use other packages there.

By the way, I just published a menu package for BS 4, that may be of interest for you.

See https://github.com/marvinlabs/laravel-menus ;)