ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Required dropdown field

December 03, 2010 7:20pm

Subscribe [4]
  • #1 / Dec 03, 2010 7:20pm

    julzmon

    44 posts

    How do I setup a required dropdown field? If I use Select Dropdown custom field and fill it with options it’s automatically selects the first item. How do I leave a blank space and get an error if I haven’t selected anything from the dropdown?

    Thanks

  • #2 / Dec 03, 2010 8:55pm

    Jose B

    313 posts

    I do not know if this will help, but have you considered making the first item a small period “.”?

  • #3 / Dec 04, 2010 1:19am

    Roi Agneta

    352 posts

    To set a default value in the dropdown you can do this:

    <option selected="selected" value="">-- Choose --</option>

    Change “—Choose—” to whatever you want.  As for making it a required field, I am not sure that is possible since a dropdown always has a value by its very nature.  You could use some Javascript to check that it is not set to the default value.

  • #4 / Dec 05, 2010 3:18pm

    Greg Salt

    3988 posts

    Hi julzmon,

    This is not possible with the default Select field. You can certainly create a Fieldtype to enable this functionality though. Shall I move this thread to the Development & Programming forum so that you can get some community input into this?

    Cheers

    Greg

  • #5 / Dec 05, 2010 6:52pm

    julzmon

    44 posts

    I actually figured it out with a little help from Pixel & Tonic.
    If you use their P&T Dropdown fieldtype and give the first line 4 spaces. Actually you can also create optgroup by leaving no space for title and 4 spaces before the option.

    i.e.

    Title
        One
        Two
    Title2
        One
        Two
  • #6 / Dec 06, 2010 9:54am

    Sue Crocker

    26054 posts

    Hi, julzmon. Glad you found a solution.. Don’t hesitate to post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases