Closed ghost closed 7 years ago
@ricardovigatti, sorry for the delay. You can indeed set the ID, just as you are in the above example.
{!! Form::hidden('name', 'value')->id('id') !!}
Outputs:
<input type="hidden" name="name" id="wat">
This works in both form and bootforms packages (bootforms actually delegates this to the base form builder) using PHP's magic methods. Any method not defined by form/bootforms will delegate to attribute()
. Example...
{!! Form::hidden('name', 'value')->attribute('lol', 'catz') !!}
{!! Form::hidden('name', 'value')->lol('catz') !!}
Both of the above examples will output:
<input type="hidden" name="name" lol="catz">
I'm getting a FatalErrorException: Call to a member function id() on a non-object.
And i'm trying to use exactly like said above.
{!! Form::hidden('name', 'value')->id('someid') !!}
// with "attribute", the error is the same
{!! Form::hidden('name', 'value')->attribute('id', 'someid') !!}
I don't know how can i check this, you have any tip for me to start digging into?
@ricardovigatti weird. Can you confirm which package version you have installed? If you are on mac or linux, you should be able to run this to find out which version is currently installed:
cat composer.lock | grep '"name": "adamwathan/form"' -C 1
i'm on Windows, anyway, i'm using the last version, tagged as v0.8.10.
I decided to try again and see whats happens:
// did not work
{!! Form::hidden('name', 'value')->attribute('id', 'someid') !!}
// surprise! that works.
{!! BootForm::hidden('name', 'value')->attribute('id', 'someid') !!}
@ricardovigatti Curious what Form
facade/alias is set to in your /config/app.php
? It should look something like this:
'BootForm' => AdamWathan\BootForms\Facades\BootForm::class,
'Form' => AdamWathan\Form\Facades\Form::class,
And there should be nothing else bound to Form
. We use both BootForm::
and Form::
in our blade views without issue here.
@JesseLeite Awesome! You found the problem.
I remembered of changing my facades to use the Form Collective package.
'AdamForm' => 'AdamWathan\Form\Facades\Form',
'BootForm' => 'AdamWathan\BootForms\Facades\BootForm',
// ...
'Form' => 'Collective\Html\FormFacade',
'Html' => 'Collective\Html\HtmlFacade',
Now i'm using AdamForm::hidden()
in my views.
Thanks.
@ricardovigatti No problem. Don't mix your drugs! And definitely don't mix your form packages! Adam's base form package is (IMO) a huge improvement to the collective form package. Unless you are using that collective form package, you could just rip it out ;)
I'm trying to set the ID for my hidden input. Something like:
{{ Form::hidden('name', 'value')->id('id') }}
I've searched here and at BootForm package and didn't find a solution.
Thanks.