Tagged: 

Viewing 7 reply threads
  • Author
    Posts
    • #7260
      Dan
      Participant

      Hi, Is there a way to auto populate the add more fields by default?

      For example, on creation of a new post I would like to display 3 text fields, but the user could delete or change these as appropriate?

    • #7261
      Dan
      Participant

      This is a screenshot of desired output on adding a post

      Attachments:
      You must be logged in to view attached files.
    • #7263
      Phil
      Participant

      I’m guessing you could give the available_sections a value that is an array like this:

      'value' => array('Default 1', 'Default 2', 'Default 3')

    • #7264
      Dan
      Participant

      Hi phil,

      I’ve tried this, doesn’t seem to work as a child add more.

      I’ve done a work around for now, adding this into a settings page and showing this as a multi select.

      Cheers

    • #7266
      Phil
      Participant

      This code produces the attached screenshot for me (Piklist 0.9.9.9, WP 4.6):

      
      piklist('field', array(
        'type' => 'group'
        ,'field' => 'classes'
        ,'label' => 'Classes'
        ,'add_more' => true
        ,'fields' => array(
          array(
            'type' => 'text'
            ,'field' => 'class'
            ,'label' => 'Class Name'
            ,'columns' => 12
          )
          ,array(
            'type' => 'text'
            ,'field' => 'members'
            ,'label' => 'Members'
            ,'columns' => 6
          )
          ,array(
            'type' => 'text'
            ,'field' => 'non_members'
            ,'label' => 'Non-Members'
            ,'columns' => 6
          )
          ,array(
            'type' => 'text'
            ,'field' => 'section'
            // ,'label' => 'Section'
            ,'add_more' => true
            ,'columns' => 12
            ,'attributes' => array('placeholder' => 'Section Name')
            ,'value' => array('Section 1', 'Section 2', 'Section 3')
          )
        )
      ));
      

      But when you say it “doesn’t seem to work as a child add more,” perhaps you are referring to this limitation:

      Currently, default values for our Add-Mores only work on the initial field. We have it on our list to make it work on every add_more.

      This means that if you add an additional class, it won’t display the three default sections. Only the initial class will show defaults.

      Attachments:
      You must be logged in to view attached files.
    • #7269
      Dan
      Participant

      That’s really odd, I’m also on Piklist 0.9.9.9, WP 4.6 but I do not get the default fields come through?

      Copied your example into mine just in case I had a typo, but still not getting the desired results.

      <?php
      /*
      Title: Classes
      Post Type: mrc-event
      Order: 200
      */
      
      piklist('field', array(
        'type' => 'group'
        ,'field' => 'classes'
        ,'label' => 'Classes'
        ,'add_more' => true
        ,'fields' => array(
          array(
            'type' => 'text'
            ,'field' => 'class'
            ,'label' => 'Class Name'
            ,'columns' => 12
          )
          ,array(
            'type' => 'text'
            ,'field' => 'members'
            ,'label' => 'Members'
            ,'columns' => 6
          )
          ,array(
            'type' => 'text'
            ,'field' => 'non_members'
            ,'label' => 'Non-Members'
            ,'columns' => 6
          )
          ,array(
            'type' => 'text'
            ,'field' => 'section'
            // ,'label' => 'Section'
            ,'add_more' => true
            ,'columns' => 12
            ,'attributes' => array('placeholder' => 'Section Name')
            ,'value' => array('Section 1', 'Section 2', 'Section 3')
          )
        )
      ));
      Attachments:
      You must be logged in to view attached files.
    • #7271
      Phil
      Participant

      @Dan I owe you an apology because I posted all that forgetting that I had applied this patch, So I wasn’t working with a clean copy of Piklist. When I revert that patch, I see the exact same problem you described.

      I guess it’s up to you whether to modify the Piklist core files with that patch. Again, my apologies.

    • #7272
      Dan
      Participant

      Don’t apologise, this is exactly what I needed. Thank you!

Viewing 7 reply threads
  • You must be logged in to reply to this topic.