Viewing 6 reply threads
  • Author
    Posts
    • #3407
      justin
      Member

      I am trying to add a “notes” section to a post type that will record the current user and date of the note. So i created a “group” field type that had 2 text fields that I tried to lock on_post_status and auto insert the value, and have one textfield option. The problem is that by using the on_post_status it does not work correctly Please see photo. It does not allow me to add multiple notes.

      
      piklist('field', array(
          'type' => 'group'
          ,'field' => 'reg_notes'
          ,'add_more' => true
          ,'label' => 'Notes'
          ,'description' => 'You can add private notes below for internal reference that only team members will see.'
          ,'fields' => array(
            array(
              'type' => 'text'
              ,'field' => 'note_author'
      		,'value' => $current_user->display_name
              ,'columns' => 3
      		,'on_post_status' => array(
      			'value' => 'approved'
      		)
            )
            ,array(
              'type' => 'text'
              ,'field' => 'note_date'
      		,'value' => date("m/d/y")
              ,'columns' => 2
      		,'on_post_status' => array(
      			'value' => 'approved'
      		)
            )
            ,array(
              'type' => 'textarea'
              ,'field' => 'note_text'
              ,'columns' => 7
              ,'attributes' => array(
                'placeholder' => 'Your Notes'
              )
            )
          )
        ));
      
      Attachments:
      You must be logged in to view attached files.
    • #3416
      Steve
      Keymaster

      @justin– on_post_status is designed to lock a field on a certain post status. Are you trying to lock past notes?

    • #3421
      justin
      Member

      Ideally that would be great, but I could not figure that out. So instead I was just going to have 2 of the 3 fields in the group always be locked because I automatically set the value to the current date and the current user. But when I try and lock those two fields in the group that allows for add_more, the add more button disappears, and I can now only add a single note instead of multiple notes.

      GROUP with add more functionality set to true

      • Name (This field will be automatically set to current user, and always be locked)
      • Date (This field will be automatically set to current date and always be locked)
      • Notes (This field will never be locked-unless it was possible to lock past notes, but that is not what the code above is trying to do.)
    • #3423
      Steve
      Keymaster

      @justin– No reason to get all fancy and use get_post_status… the standard HTML attribute readonly will work, and Piklist makes it super easy to add attributes.

      Try this:

      piklist('field', array(
        'type' => 'group'
        ,'field' => 'reg_notes'
        ,'add_more' => true
        ,'label' => 'Notes'
        ,'description' => 'You can add private notes below for internal reference that only team members will see.'
        ,'fields' => array(
          array(
            'type' => 'text'
            ,'field' => 'note_author'
            ,'value' => $current_user->display_name
            ,'columns' => 3
            ,'attributes' => array(
              'readonly' => 'readonly'
            )
          )
          ,array(
            'type' => 'text'
            ,'field' => 'note_date'
            ,'value' => date("m/d/y")
            ,'columns' => 2
            ,'attributes' => array(
              'readonly' => 'readonly'
            )
          )
          ,array(
            'type' => 'textarea'
            ,'field' => 'note_text'
            ,'columns' => 7
            ,'attributes' => array(
              'placeholder' => 'Your Notes'
            )
          )
        )
      ));
      
    • #3429
      justin
      Member

      Thank you. Did not event think about using that. The only other thing now that I am finding is that when you add another field, it is not auto-populated by the value I have inputted. They are just blank.

    • #3430
      Steve
      Keymaster

      @justin– The reason that only the first add-more sets the default is to make a better user experience. Change the fields from text to html and it will work:

      piklist('field', array(
        'type' => 'group'
        ,'field' => 'reg_notes'
        ,'add_more' => true
        ,'label' => 'Notes'
        ,'description' => 'You can add private notes below for internal reference that only team members will see.'
        ,'fields' => array(
          array(
            'type' => 'html'
            ,'field' => 'note_author'
            ,'value' => $current_user->display_name
            ,'columns' => 3
          )
          ,array(
            'type' => 'html'
            ,'field' => 'note_date'
            ,'value' => date("m/d/y")
            ,'columns' => 2
          )
          ,array(
            'type' => 'textarea'
            ,'field' => 'note_text'
            ,'columns' => 7
            ,'attributes' => array(
              'placeholder' => 'Your Notes'
            )
          )
        )
      ));
      
    • #3431
      justin
      Member

      Thank you for your help.

Viewing 6 reply threads
  • The topic ‘on_post_status and Add more’ is closed to new replies.