Skip to content
This repository has been archived by the owner on Feb 26, 2018. It is now read-only.

Empty Option #102

Open
hugofabricio opened this issue May 15, 2016 · 1 comment
Open

Empty Option #102

hugofabricio opened this issue May 15, 2016 · 1 comment

Comments

@hugofabricio
Copy link

hugofabricio commented May 15, 2016

Hi,

How to set empty option in select?

@hugofabricio hugofabricio changed the title Null Option Empty Option May 15, 2016
@GregPeden
Copy link

If you want an empty or "null" option in a select list, you need to include an empty option. This is external to BootForm, it's just how HTML works.

Example from a random piece of my code, prepared to :

$data['offices_list'] = ['' => ''] + Office::orderBy('name')->pluck('name', 'id')->toArray();

Then you'd load up the $offices_list array using BootForm. Default option = first option = blank. If validation fails, on reload the default will be whatever the user entered last time, assuming the select field is normal HTML without JavaScript fanciness.

Keep in mind that means the user can easily submit a form with this blank field selected, so make sure you perform necessary validation server-side before saving, which you should be doing anyway to protect from shenanigans.

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

No branches or pull requests

2 participants