Viewing 12 reply threads
  • Author
    Posts
    • #3585
      diegoliv
      Member

      Hi,

      I’ve been trying to setup a group (with “add more”) with a file uploader with Piklist, and it looks fine. But I noticed a strange issue. With the first group, I select a file and it’s ok. But, for the subsequent added groups, there is a hidden field with an undefined value that counts as a file.

      Here is my grouped field code:

        piklist('field', array(
          'type' => 'group',
          'field' => 'home_slideshow',
          'label' => __( 'Slideshow' ),
          'add_more' => true,
          'fields' => array(
      		  array(
      		    'type' => 'file',
      		    'field' => 'slider_img',
      		    'label' => __( 'Selecionar Imagem' ),
      		    'description' => __('Selecione uma imagem para o slide.' ),
      		    'options' => array(
      		      'modal_title' => __( 'Selecionar imagem do slide' ),
      		      'button' => __( 'Selecionar' )
      		    ),
      			  'validate' => array(
      			    array(
      			      'type' => 'limit',
      			      'options' => array(
      			        'min' => 1,
      			        'max' => 1
      			      )
      			    )
      			  )
      		  ),
      		  array(
      		    'type' => 'text',
      		    'field' => 'slide_title',
      		    'label' => __( 'Título do Slide' ),
      		    'columns' => 12
      		  ),
      		  array(
      		    'type' => 'text',
      		    'field' => 'slide_link',
      		    'label' => __( 'Link do Slide' ),
      		    'columns' => 12
      		  ),
          )
        ));

      And, when I check the home_slideshow array, I got this:

      		Array
      (
          [0] => Array
              (
                  [slider_img] => Array
                      (
                          [0] => Array
                              (
                                  [0] => 1526
                              )
      
                          [1] => Array
                              (
                                  [0] => undefined
                                  [1] => 1525
                              )
      
                      )
      
                  [slide_title] => Array
                      (
                          [0] => Slide 01
                          [1] => Slide 02
                      )
      
                  [slide_link] => Array
                      (
                          [0] => http://site.com/
                          [1] => http://site.com/
                      )
      
              )
      
      )

      When I check the source code from the group backend, I noticed this hidden field:

      <input type="hidden" name="_post_meta[home_slideshow][slider_img][2][]" value="undefined" data-piklist-field-group="729944c" data-piklist-field-addmore="true" class="_post_meta_home_slideshow_slider_img" data-piklist-original-id="_post_meta_home_slideshow_slider_img_0">.

      If I update the page, then add another image, then remove it and update it again, the undefined value is removed. Also, when I add a new group and add multiple images, the sortable function doesn’t work for that new group. But, if I update the page, it starts to work again.

      Am I doing something wrong?

      Thanks!

    • #3598
      Steve
      Keymaster

      @diegoliv– I can’t reproduce the ‘undefined’ issue and will still look into that. As for the sorting and add-mores, try removing your validation rule. It’s limiting you to only one add_more.

      Remove this, or increase the max.

       'validate' => array(
      			    array(
      			      'type' => 'limit',
      			      'options' => array(
      			        'min' => 1,
      			        'max' => 1
      			      )
      			    )
      
    • #3603
      diegoliv
      Member

      Hi, Steve! Thanks for the answer. Actually, I forgot to remote it from the snippet above. The issue if the add-mores and the sorting from files added into it still happens without the validation rules.

      If you need to, I can give you temporary admin access to the WP install that is happening this, so you guys can investigate better.

      Thanks!

    • #3604
      Steve
      Keymaster

      What version of Piklist do you have installed?

    • #3605
      diegoliv
      Member

      The installed Piklist version is 0.9.4.25.

    • #3607
      Steve
      Keymaster

      I can’t reproduce. Try disabling other plugins to see if that helps.

    • #3610
      diegoliv
      Member

      Hi, Steve!

      Sorry for the delay. I tried that, deactivated all plugins and keeped only Piklist. The issue still happens.

      As I said, if you want, I could give you access to the particular install where this is happening!

      Thanks!

    • #3616
      jcrist
      Member

      I was having the same issue with a similar setup — a grouped repeater field with a file upload. The first image returned fine but the rest would return with [0] => undefined, [1] => 123.

      I ended up changing the setup and utilizing the built-in Media Details instead.

    • #3623
      diegoliv
      Member

      Hey, jcrist, that’s the exactly same issue that I’m having right now! And it’s good that it worked for you with just the media details. Unfortunately I need to build a repeater with the media upload and a couple more fields. But at least it’s good to know that I’m not the only one facing this behavior!

    • #3625
      jcrist
      Member

      I ended up using attachment_fields_to_edit filter and adding the fields I needed. This saved me from having to use a repeater as the user can select any images they would like. However a new problem arose in that after adding the images, if you click on an image to edit the fields you are taken to the add new image screen instead without the image selected, so selecting it adds the images again 🙁

    • #3929
      Mehdi Salem
      Member

      FIX:

      Dear Steve,

      Same issue here guys and I can tell you: it has been a tricky one to track down…

      I think the problem is a very hidden glitch in the Piklist’s scripts running on the posts edit page and that handles dynamically the changes made while adding/removing files and add_mores.

      The <input value=”undefined”… problem showed up for me with file uploads AND textarea fields as well in the add_more groups.

      Steve, if you have note yet being able to reproduce the hidden input “undefined” values problem, let me know and I will reply with exact steps to witness this on the latest version of Piklist as of today: 0.9.4.27

      Awesome framework by the way, Keep up the great work guys!

      In the mean time, her is a QUICK FIX to address this issue with jQuery in case somebody can benefit:

      Here is how I fixed the issue with a little jQuery script, just add this code after your Piklist header and before your Piklist groups/fields code, using setTimeout in a loop is not elegant but this is the only simple quick way to fix what I consider an annoying issue: (make sure to replace “YOUR_FIELD_GROUP_NAME” to match your actual field names)
      _______________________________________________________

      // YOUR PIKLIST HEADER HERE… for example:
      /*
      Title: Cover Page Listing
      Post Type: sepia,black_and_white,color,conservation
      */

      // ADD THE FIX HERE (note the closing php tag before the script and the opening tag at the end of the fix)

      ?><script language="javascript" type="text/javascript">
        jQuery( document ).ready(function() {
          /**** PIKLIST GROUP ADD_MORE HIDDEN INPUT UNDEFINED VALUES BUG FIX:
                TO OVOID UNDEFINED VALUES TO MESS UP THE SERIALIZED ARRAY STORED IN THE DATABASE
          ****/
          function fixPiklistUndefinedInputVals() 
          {
            jQuery('.piklist-field-list-item > input[value=undefined]').val('');
            jQuery('#_YOUR_FIELD_GROUP_NAME div.piklist-upload-file-preview input[value=undefined]').val('');
            setTimeout(fixPiklistUndefinedInputVals, 500);
          }
          fixPiklistUndefinedInputVals();
        });
      </script><?php
      

      // ADD YOUR PIKLIST ADD_MORE FIELDS HERE……
      …..
      _____________________________________________________

      Also I see that you guys noticed another issue: that we cannot use the limit validation process on add_more groups… So let me know if you need a fix, I wrote a script to solve this too, it will allow you to limit the number of files uploaded per group, not as solid as server side validation but it will make your clients happy and confident 😉

      Cheers!

    • #3937
      Steve
      Keymaster

      @mnlearth– I just emailed you our latest beta to test against.

    • #3939
      dryan1144
      Member

      I just want to chime in and say I’m experiencing the same issue and that the js that @mnlearth posted solved the issue for me. Happy to try out any other solutions you might have and report back.

Viewing 12 reply threads
  • The topic ‘File Upload – Undefined item’ is closed to new replies.