Viewing 2 reply threads
  • Author
    Posts
    • #5999
      Rachel
      Member

      Is there a way to have a piklist checkbox field with only one choice that can be true or false based on whether it is checked?

      I tried the following, but send_email isn’t given a value unless it’s checked, and I’d like to have it set the value to 0 when it is not checked.

      piklist('field', array(
           'type' => 'checkbox',
           'field' => 'send_email',
           'label' => 'Send Email?',
           'value' => '1',
           'attributes' => array(
              'class' => 'text'
            ),
           'columns' => 6,
           'choices' => array(
             '1' => 'Enable'
           )
         )
      )

      In the past, I’ve used the workaround of having radio buttons, but I’d really like to just have an enable checkbox.

      My workaround:

      piklist('field', array(
           'type' => 'radio',
           'field' => 'send_email',
           'label' => 'Send Email?',
           'value' => 1,
           'list' => true,
           'columns' => 6,
           'choices' => array(
             1 => 'Enable',
             0 => 'Disable'
            )
         )
       )
    • #6008
      Steve
      Keymaster

      @rachel– In the first example you should get ‘1’ if enabled, and empty if not enabled. Would that work?

    • #6017
      Rachel
      Member

      @Steve I wanted to see if there was an explicit false value that could be set, but I can make this work.

      Thanks!
      Rachel

Viewing 2 reply threads
  • The topic ‘Checkbox with only one choice’ is closed to new replies.