Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toggle of empty field in FormBuilder::select #743

Closed
atrauzzi opened this issue Mar 28, 2013 · 4 comments
Closed

Allow toggle of empty field in FormBuilder::select #743

atrauzzi opened this issue Mar 28, 2013 · 4 comments

Comments

@atrauzzi
Copy link
Contributor

If a single select field is optional, convention is usually that you include a blank option along with the list of options.

When I'm assigning the list of values via a query from the database, I currently have no way of telling it to inject a blank option (which should appear first and checked by default if no value is set).

Ideally something like:

{{ Form::select(..., ..., ..., array('addEmpty' => true)) }}

...would do nicely!

@taylorotwell
Copy link
Member

Can't you just prepend an element to the array you are passing. I don't want to bake more option arrays like this into the method.

@atrauzzi
Copy link
Contributor Author

Yes, prepending does work, although I didn't know if it would be considered a data hack or not.

@phikes
Copy link

phikes commented May 27, 2014

That answer is ignorant. You will be code duplicating, an option for this would be appropriate.

@JorisDebonnet
Copy link

This is the top result on Google for "laravel form builder empty option", that's why I am posting here.

It can be a pain to manually add an empty option for a Form::select element. A solution for id=>value Collections is passing $items = [''=>''] + Item::lists('value','id').toArray(). But that will need to be done every time an empty top option is required... it creates messy code.

Since the FormBuilder has moved to a separate repository however, let us move to laravelcollective/html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants