We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    Hi,

    How do I retain the value of a dropdown select (html <select>... <option> ...</select>) with Formit?

    Right now it looses its selected value after the form check fails.

    Thanks.
      MODx Revolution / MAMP / OS X
      • 1778
      • 659 Posts
      Hello

      I achieved this like that, it works... Maybe there’s another way to do it, but this one is easy to understand.
      The important thing is the part after the "value" in each option. You have to use an output modifier in each option...
      <select id="mySelect" name="mySelect" value="[[+mySselect]]">
        <option id="opt1" name="opt1" value="opt1" [[+fi.mySelect:is=`opt1`:then=`selected="selected"]]>OPT 1</option>
        <option id="opt2" name="opt2" value="opt2" [[+fi.mySelect:is=`opt2`:then=`selected="selected"]]>OPT 2</option>
      </select>
      


      If you need more explanations feel free to contact me
      Hope this helps
      Cheers
        • 27519
        • 275 Posts
        Hi,

        Thanks for the reply.

        I implemented:

          <select name='title' id='title' value='[[+title]]'>
            <option value='' [[+fi.title:is=``:then=`selected="selected"`]]></option>
            <option value='Miss' [[+fi.title:is=`Miss`:then=`selected="selected"`]]>Miss</option>
            <option value='Mr.' [[+fi.title:is=`Mr.`:then=`selected="selected"`]]>Mr.</option>
            <option value='Mrs.' [[+fi.title:is=`Mrs.`:then=`selected="selected"`]]>Mrs.</option>
            <option value='Ms.' [[+fi.title:is=`Ms.`:then=`selected="selected"`]]>Ms.</option>
          </select>
        


        I added closing ` in then-clause.

        I doesn’t seem to work.

        Any clue what’s wrong??

        Thanks for your help!
          MODx Revolution / MAMP / OS X
          • 1778
          • 659 Posts
          Hello

          Probably my fault, in the "select" the value must be "[[+fi.title]]" not "[[+title]]", in my example it should be

          <select id="mySelect" name="mySelect" value="[[+fi.mySselect]]">
          <option id="opt1" name="opt1" value="opt1" [[+fi.mySelect:is=`opt1`:then=`selected="selected"]]>OPT 1</option>
          <option id="opt2" name="opt2" value="opt2" [[+fi.mySelect:is=`opt2`:then=`selected="selected"]]>OPT 2</option>
          </select>

          And then it should work... Sorry for this error in my example
          Cheers
            • 27519
            • 275 Posts
            Yes, got it!

            Great stuff, thanks again!

            Cheers
              MODx Revolution / MAMP / OS X