- This topic has 5 replies, 2 voices, and was last updated 6 years, 7 months ago by
Steve.
-
AuthorPosts
-
-
July 6, 2015 at 11:00 am #3963
GreggMemberHi Steve
I updated a settings function to impose a limit of 1 file upload for the site logo as you can see in the attached.
However, on save, I keep getting the error “Add File must have exactly 1 items added.” even though I’ve only selected one image.
I checked the database and I don’t see any settings for this field so I can’t find any conflicts in the DB.
Prior to this, I ran into a problem when I replaced the image with another and the setting created an array on the backend. The image wasn’t displayed on the front-end given that it was referencing the first instance in the array if that makes sense.
Any thoughts?
Here’s the settings code:
piklist('field', array( 'type' => 'checkbox' ,'field' => 'gwfg_use_image_for_logo' ,'value' => '' // ,'label' => 'Use image for logo?' ,'description' => 'If left unchecked, plain text will be used instead (generated from site name).' ,'choices' => array( 'use-logo' => 'Yes' ) )); piklist('field', array( 'type' => 'file' ,'field' => 'gwfg_site_logo' ,'label' => 'Add File','piklist' ,'description' => __('Upload your movie logo.','piklist') ,'options' => array( 'modal_title' => __('Add File','piklist') ,'button' => __('Add','piklist') ) ,'validate' => array( array( 'type' => 'limit' ,'options' => array( 'min' => 1 ,'max' => 1 ) ) ) ));Attachments:
You must be logged in to view attached files. -
July 6, 2015 at 3:44 pm #3966
SteveKeymaster@gregg– This is working for me. What version of Piklist are you using?
The only error is see is this line:
,'label' => 'Add File','piklist'Should be
,'label' => __('Add File','piklist') -
July 6, 2015 at 6:21 pm #3967
GreggMember@steve – I was one version behind and just updated, but still having the same issue running locally with MAMP. I’ll do a little more digging through the database tonight to see whether I can spot the cause.
-
July 7, 2015 at 12:09 am #3968
SteveKeymasterA good place to start is class-piklist-validate.php. Let me know what’s getting passed to validate_limit(). Specifically, I need to see $value, $field and $argument. Let me know if you need help.
-
July 7, 2015 at 8:46 am #3971
GreggMemberOn closer inspection, I discovered that the settings array had an ID of the old attachment. Changing that to the current / revised image ID did the trick. I’ll do some more testing to see whether there are any issues with switching images, but go ahead and close the ticket.
Thanks so much for your help Steve.
-
July 7, 2015 at 10:02 am #3972
SteveKeymasterMy pleasure… always happy to help. Closing ticket.
-
-
AuthorPosts
- The topic ‘File Limit Exactly 1 Error’ is closed to new replies.