How can I repopulate my dropdown on a front-end form? I am allowing guest registrations - everything is working fine. I am hung up on getting my drop down menu to repopulate/hold its value if there are any errors while submitting.

I have a states field in the CP which is a dropdown.

Within my twig template I have this:

{#
 # Get all of the states.
 #
 #}
 {% set states = craft.fields.getFieldByHandle('states').getFieldType.options %}
 {% if states|length %}
     &lt;div class="form-group"&gt;
         &lt;label for="state"&gt;State&lt;/label&gt;
         &lt;select id="state" name="fields[address][state]" class="form-control"&gt;
             &lt;option value=""&gt;Select&lt;/option&gt;
             {% for option in states %}
                 &lt;option val="{{ option.value }}"
                     {%- if account is defined and option.value in account.address.state %} selected {% endif -%}&gt;
                     {{ option.label }}
                 &lt;/option&gt;
             {% endfor %}
         &lt;/select&gt;
     &lt;/div&gt;
 {% endif %}
 {% if account is defined %}
     {{ errorList(account.getErrors('state')) }}
 {% endif %}


I am using SmartMap to capture my address hence the name of fields[address][state]. 

Just doing this:

{%- if account is defined %} selected {% endif -%}


Gets the last option selected, so I know account is getting defined, its something in my and part.

All of my data is getting captured correctly, I just can't see past the obvious here I guess.

SOLUTION

Thanks to @carlcs I found that the value of my state field was getting saved as the label. I'm not sure if thats a function of SmartMap, or something else I might have done.

Here is what I ended up with:

...
&lt;option value=""&gt;Select&lt;/option&gt;
{% for option in states %}
    &lt;option val="{{ option.value }}"
        {%- if account is defined and option.label in account.address.state %} selected {% endif -%}&gt;
        {{ option.label }}
    &lt;/option&gt;
{% endfor %}


Alternatively, here is how I was able to repopulate a "normal" drop-down (not address/SmartMap):

...
&lt;option value=""&gt;Select&lt;/option&gt;
{% for option in myField %}
    &lt;option val="{{ option.value }}"
    {%- if account is defined and option.label in account.myField.label %} selected {% endif -%}&gt;
       {{ option.label }}
    &lt;/option&gt;
{% endfor %}


I think it's also worth noting that by setting myField as a required field in the CP, I needed to hard-code the &lt;option value=""&gt;Select&lt;/option&gt; in the template rather than putting it as a field value. When I had it as a field value, I (think) Craft was accepting that as a selected value and I was not getting the error message.
You could dump the account variable to see why the conditional doesn't work as you're expecting. I don't really see the reason to why you'd need the in containment test, but I'd just use dump for debugging.