Tagged: 

Viewing 5 reply threads
  • Author
    Posts
    • #5308
      kabadabra
      Member

      Hi there,

      Is there a way to set certain options when using select fields?

      For example

      Electronics (Parent)
      – Computers (Child)
      – Mobile (Child)

      Would like to set all parent options in a select list to be disabled.

    • #5329
      Steve
      Keymaster

      @kabadabra– Piklist uses standard HTML form attributes.

      Add this to any Piklist field array that you want disabled:

      'attributes' => array(
        'disabled' => 'disabled'
      )
      

      This will make the form disabled

    • #5342
      kabadabra
      Member

      Hi Steve, I think you misunderstood what I’m trying to do.

      I have a select list like the following: https://dl.dropboxusercontent.com/s/cubjkioi629s2h3/2015-12-14%20at%2021.33.jpg

      I want to make certain <options> disabled but not sure how you set an attribute per choice? The code that you’ve given above would make a whole field or select disabled.

      I managed to build a workaround as per in my screenshot for getting custom taxonomies saved from the front end. But it’s a long way around to something potentially simple.

      Appreciate your feedback and thoughts as always, thank you.

    • #5344
      Steve
      Keymaster

      I think you mean OPTION GROUPS

      You can see an example in Piklist Demos > Common > Lists > Select with Option Groups

        piklist('field', array(
          'type' => 'select'
          ,'field' => 'select_optgroup'
          ,'label' => __('Select with Option Groups', 'piklist-demo')
          ,'value' => 'third'
          ,'choices' => array(
            'Group 1' => array(
              'first' => __('First Choice', 'piklist-demo')
              ,'second' => __('Second Choice', 'piklist-demo')
              ,'third' => __('Third Choice', 'piklist-demo')
            )
            ,'Group 2' => array(
              'first' => __('First Choice', 'piklist-demo')
              ,'second' => __('Second Choice', 'piklist-demo')
              ,'third' => __('Third Choice', 'piklist-demo')
            )
          )
        ));
      

      Let us know if this works for you.

    • #5345
      kabadabra
      Member

      Perfect, this makes sense now. Thanks Steve! LEGEND!

    • #5348
      Steve
      Keymaster

      Nice! Closing ticket.

Viewing 5 reply threads
  • The topic ‘Disable options on select’ is closed to new replies.