Menu

SmartForm select entities

Help
2002-11-08
2004-01-22
  • Mark Britton

    Mark Britton - 2002-11-08

    How do you choose which item is selected by default in a select list.  Same question for choosing the checked options in a checkbox or radio buttons?

     
    • Mattias Segnestam

      My knowledge only reaches as far as setting a default value in an XML-SmartForm.
      That you can do in the <PARAMETER> element with the code:

      <VAR    name = "value"    value = "0" />

      where the value correspond to the desired valu in the <DIRECTIVE> element. For example:

              <DIRECTIVE  KEY="optionList">
                  <VAR    name = "0"          value="Option 1" />
                  <VAR    name = "1"          value="Option 2" />
                  <VAR    name = "2"          value="Option 3" />
                  <VAR    name = "3"          value="Option 4" />
              </DIRECTIVE>

      Hope this helps in some way.

      I will look and see if I can find any way of  add a directive within the module, have to get back to you on that one, (if the pro's doesn't beat me to it).

       
    • Mattias Segnestam

      After going through some code, I found one way to this.
      If yo add a select list like this for example:

      $thisSelect =& $myForm->add('sex','Sex','select',true,'',array('multiple'=>true));

      And then add some options.

              $thisSelect->addOption("Male","Male");
              $thisSelect->addOption("Female","Female");
              $thisSelect->addOption("Something Inbetween","NULL");

      You could then set the default option with.

      $thisSelect->value = "Female";

      Don't know if its the right way of doing it but it worked when I did a quick test.

      Both my examples are with select lists. Have to get back to you with some examples of checkboxes and radiobuttons.

       
      • David Weinraub

        David Weinraub - 2004-01-09

        Any progress on the checkBoxes and radioButtons? That is, after adding a checkBoxEntity to a SmartForm, how do I set it to be checked!

        Thanks!

         
    • Mark Britton

      Mark Britton - 2002-11-11

      Ok, this was really simple...don't know how I missed it in the docs:
      In the above example, the add line would look like:
      $thisSelect =& $myForm->add('sex','Sex','select',true,'Female',array('multiple'=>true));

       
      • Shannon Weyrick

        Shannon Weyrick - 2002-11-11

        yes and in addition, for a Multiple select entity, you can set the items to be selected by passing the selected values as either a comma delimited list, or an array:

        $thisSelect =& $myForm->add('sex','Sex','select',true,'Female.Male',array('multiple'=>true));

        or

        $thisSelect =& $myForm->add('sex','Sex','select',true,array('Female','Male'),array('multiple'=>true));

        shannon

         
    • Mattias Segnestam

      Well, I missed that one too. Nice to know.

       
    • David Weinraub

      David Weinraub - 2004-01-22

      A sample for checkBoxes:

      $value = 1; // or 0;
      $eCB =& $myForm->add('myCheckBox', 'True?', 'checkBox', false, $value);
      $eCB->addOption('', 1);

       

Log in to post a comment.

MongoDB Logo MongoDB