Empty Drop-down List Option
Posted: 23 October 2006 12:52 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  2006-01-05

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.

File Attachments
ext.empty_options_100.zip  (File Size: 2KB - Downloads: 379)
 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 23 October 2006 01:46 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14145
Joined  2002-06-03

Why not just do the following?

{if shirt_color != '--'}...{/if}

 Signature 
Profile
 
 
Posted: 23 October 2006 02:07 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  2006-01-05

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.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 23 October 2006 02:12 PM   [ Ignore ]   [ # 3 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14145
Joined  2002-06-03

Yep, different animal altogether.  Continue!

 Signature 
Profile
 
 
Posted: 23 October 2006 02:35 PM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  2006-01-05

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!

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 12 November 2006 10:24 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1394
Joined  2006-03-26

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.

 Signature 

ryan masuga
Masuga DesignMember, EE Pro Network
Peruse my EE Plugins & Extensions

Profile
 
 
Posted: 13 November 2006 10:00 AM   [ Ignore ]   [ # 6 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  14145
Joined  2002-06-03

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.

 Signature 
Profile
 
 
Posted: 07 July 2007 04:05 PM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1401
Joined  2005-01-15

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

 Signature 

EE Duration Tags | {view_count_total}

Profile
 
 
Posted: 28 September 2007 07:46 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  218
Joined  2004-02-27

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?

Profile
 
 
Posted: 29 September 2007 07:37 AM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1183
Joined  2006-01-05

It does not affect the member sign up form.

 Signature 

================================================
    Mark Huot
    http://markhuot.com
================================================

Profile
 
 
Posted: 08 December 2007 11:08 AM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  757
Joined  2007-04-14

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?

 Signature 

Michael Rubens | hothousegraphix
Making the simple complicated is commonplace; making the complicated simple, awesomely simple, that’s creativity. - Charles Mingus

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 59014 Total Logged-in Users: 24
Total Topics: 69969 Total Anonymous Users: 11
Total Replies: 376984 Total Guests: 528
Total Posts: 446953    
Members ( View Memberlist )
Newest Members:  abahkinezoAdnan RajabrasstunerjishiHa.ahn.Mnmakoto kuwatawstuckey81unexpectedlyBelle