- This topic has 12 replies, 5 voices, and was last updated 6 years, 7 months ago by
dryan1144.
-
AuthorPosts
-
-
April 8, 2015 at 12:27 pm #3585
diegolivMemberHi,
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
undefinedvalue 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_slideshowarray, 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!
-
April 9, 2015 at 9:03 am #3598
SteveKeymaster@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 ) )
-
April 9, 2015 at 10:10 am #3603
diegolivMemberHi, 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!
-
April 9, 2015 at 10:22 am #3604
SteveKeymasterWhat version of Piklist do you have installed?
-
April 9, 2015 at 10:32 am #3605
diegolivMemberThe installed Piklist version is 0.9.4.25.
-
April 9, 2015 at 12:36 pm #3607
SteveKeymasterI can’t reproduce. Try disabling other plugins to see if that helps.
-
April 9, 2015 at 3:47 pm #3610
diegolivMemberHi, 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!
-
April 9, 2015 at 10:19 pm #3616
jcristMemberI 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.
-
April 10, 2015 at 10:52 am #3623
diegolivMemberHey, 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!
-
April 10, 2015 at 11:47 am #3625
jcristMemberI 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 🙁
-
June 30, 2015 at 1:11 am #3929
Mehdi SalemMemberFIX:
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!
-
June 30, 2015 at 1:26 pm #3937
-
June 30, 2015 at 8:06 pm #3939
-
-
AuthorPosts
- The topic ‘File Upload – Undefined item’ is closed to new replies.