We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Empty Drop-down List Option

Development and Programming

Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

Currently there is no way to have an empty drop down list option appear as your first option. For example if I wanted to create a required field for shirt colors I would have to do something like follows:

– Red Green Blue

This is alright, except on the front end I can’t say {if shirt_color}…{/if} because shirt color will always be filled (even if it’s “–”).

Therefore I built an extension that will convert “–” into an empty form value. The displayed value however is customizable through the extension’s settings.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Why not just do the following?

{if shirt_color != '--'}...{/if}
       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

In the template that works fine. This extension is more for using a drop down as a required field. If you go the “–” way, the field is always filled and making it required is essentially useless. This fixes that and actually throws an error if the field isn’t filled in.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Yep, different animal altogether. Continue!

       
Mark Huot's avatar
Mark Huot
587 posts
16 years ago
Mark Huot's avatar Mark Huot

Yea, when I first head about this issue I didn’t get it either. But in the CP it makes sense why you wouldn’t want an option of “–”, while on the front end it doesn’t really matter.

continuing!

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Would there be a way (or IS there a way) to make the drop down’s value different than what the option actually shows on the screen (this is for a custom field in the Control Panel)? Just curious, say for states. I’d like my drop down to show: Select… Alaska Alabama Michigan [etc]

But I’d like the values to be: NULL AK AL MI [etc]

Maybe an extension that allows for a PHP-type array thing? So, in the drop down field I might have: Select…=>NULL Alaska=>AK Alabama=>AL Michigan=>MI

etc.

       
Derek Jones's avatar
Derek Jones
7,561 posts
16 years ago
Derek Jones's avatar Derek Jones

Yes, and extension can control both what is displayed as well as what the value of the options are for drop-down fields in the Publish page.

       
EE lover's avatar
EE lover
50 posts
15 years ago
EE lover's avatar EE lover

Thanks Mark. for almost a year I didn’t have the time to follow the forums. and now that I’m back and see all of your great works I’m really amazed.

Good luck

       
Oxygen Smith's avatar
Oxygen Smith
120 posts
15 years ago
Oxygen Smith's avatar Oxygen Smith

Thanks for this extension as well, Mark. Just for clarification, this extension doesn’t affect pulldown custom fields in the member signup form. Or is it supposed to?

       
Mark Huot's avatar
Mark Huot
587 posts
15 years ago
Mark Huot's avatar Mark Huot

It does not affect the member sign up form.

       
hothousegraphix's avatar
hothousegraphix
851 posts
15 years ago
hothousegraphix's avatar hothousegraphix

Edit… Mark…your extension seems to be doing exactly what I was looking for though I believe these results are probably unintended and due to my improper usage.

I came across your extension while looking for a solution to provide Custom Dropdown Fields the ability to group selection items; thus providing a label for each group of selections to provide a more intuitive experience for the user entering data via the Weblog Publish Panel.

Maybe I’m wrong about my application but, it seems your intent with this extension was not aimed at the back end experience? Could you clarify?

What I was doing was ignoring ignoring the use of “–” to achieve an empty option which, if I’m correct, the extension is supposed to replace with the “keyword” entered in the extension settings (is this correct?).

In my Custom Dropdown when setting the selections I added a label

// with some testing it turns out that quotes rendered to the Dropdown in the 
// Publish page so I eliminated.
<optgroup label=Identities>

So what was entered in for the dropdown selections was

<optgroup label=Identities>
Logo
System
</optgroup>
<optgroup label=Print>
Ad
Book cover
Brochure
Music CD
</optgroup>

And the result is that I get the desired label in the dropdown applied to the publish page: Identities.

Now, the thing is it’s not applied correctly - though the page validates. What occurs is the

<optgroup label=Identities>

entered as a selection for the Custom Dropdown is rendered to the Publish Page mark-up as just that, an option

//rendered Weblog Publish Page
<select name='field_id_3' class='select' >
<option value='<optgroup label=Identities>'><optgroup label=Identities></option>
<option value='Logo'>Logo</option>
<option value='System'>System</option>
<option value='' selected='selected'></option>
<option value='<optgroup label=Print>'><optgroup label=Print></option>
<option value='Ad'>Ad</option>
<option value='Book cover'>Book cover</option>
<option value='Brochure'>Brochure</option>
<option value='Music CD'>Music CD</option>
</select>

Wondering what you think about this, since it’s actually not being applied correctly with this (probably unintended) usage?

       
slorenz's avatar
slorenz
38 posts
14 years ago
slorenz's avatar slorenz

So this is a great extension and happy to see it! However, I am also using your Multi drop-down list and need to have this Empty Options functionality for that extension. Is this an option??

Never mind! Duh. Intuitively, the extension is built to simply Apple-click off every selection from the list.

       
Todd D.'s avatar
Todd D.
460 posts
14 years ago
Todd D.'s avatar Todd D.

Is this extension still functional with the latest versions of EE?

       
james Brown's avatar
james Brown
492 posts
14 years ago
james Brown's avatar james Brown

It certainly doesn’t seem to. I am running 1.6.5, and it doesn’t look like it is working on my install.

       
Todd D.'s avatar
Todd D.
460 posts
14 years ago
Todd D.'s avatar Todd D.

I never tried the extension because I didn’t receive any responses by the time I needed to move forward. However, I found a good work around that seems friendly enough.

This is what I did.

In the dropdown menu the first entry I create is ‘na’. So this would be the default value selected.

If a content contributor does not need to use the dropdown… they can simply ignore it.

Then in my templates I would use this code.

{if dropdown_field != "na"}

Here is my {dropdown_field} value.

{/if}

Essentialy making the dropdown only function when NOT EQUAL to ‘na’.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.