- This topic has 2 replies, 2 voices, and was last updated 6 years, 3 months ago by
Mehdi Salem.
-
AuthorPosts
-
-
October 10, 2015 at 7:58 pm #4522
Mehdi SalemMemberHi,
Limit validation does not work with add_more fields if users adds fields. For some reason if you set a file upload field’s limit to 1 for example, the validate_limit funcntion in class-piklist-validate.php will check 1 against the total number of add_more fields.
The limit check should be made on a per field basis as I set up in my fields, here is the code, thanks:
<?php /* Title: Content Post Type: post Order: 20 */ piklist('field', array( 'type' => 'group' ,'field' => 'folder_content_group' ,'label' => __('Gallery Photo','stopping-the-world-admin') ,'description' => __('Add photos to this folder.', 'stopping-the-world-admin') ,'help' => __('Adds a new photo to this gallery folder and sets its availability on the store.','stopping-the-world-admin') ,'add_more' => true ,'fields' => array( array( 'type' => 'file' ,'field' => 'single_photo' ,'label' => __('Photo','stopping-the-world-admin') ,'options' => array( 'modal_title' => __('Add a Photo','stopping-the-world-admin') ,'button' => __('Add','stopping-the-world-admin') ) ,'required' => true ,'validate' => array( array( 'type' => 'limit', 'options' => array( 'min' => 1, 'max' => 1 ) ) ,array( 'type' => 'image' ) ) ) ,array( 'type' => 'text' ,'field' => 'photo_title' ,'label' => __('Title','stopping-the-world-admin') ,'help' => __('Sets the photo title. This will appear bellow the photo and above the description on the Gallery Foolder post.','stopping-the-world-admin') ,'columns' => 7 ,'attributes' => array( 'placeholder' => __('Enter photo title here...', 'stopping-the-world-admin') ) ) ,array( 'type' => 'checkbox' ,'field' => 'store_availability' ,'label' => __('Store Availability','stopping-the-world-admin') ,'help' => __('(Leave unchecked if you do not want to sell this photo.)','stopping-the-world-admin') ,'columns' => 5 ,'choices' => array( 'option1' => 'Sell Stock' ,'option2' => 'Sell Print' ) ) ,array( 'type' => 'textarea' ,'field' => 'photo_description' ,'label' => __('Description','stopping-the-world-admin') ,'help' => __('Sets the photo description. This will appear bellow the photo and its title on the Gallery Folder post.','stopping-the-world-admin') ,'attributes' => array( 'rows' => 5 ,'cols' => 50 ,'placeholder' => __('Describe this photo...', 'stopping-the-world-admin') ,'maxlength' => '320' ) ) ) )); -
October 10, 2015 at 10:40 pm #4524
SteveKeymasterAnother good catch! We’ll look into it.
-
October 13, 2015 at 5:15 pm #4570
Mehdi SalemMemberHello Steve,
In addition to the problem described above, I discovered another important hidden issue with the limit validation process.
Here is the case:
1. I set the limit to 1 file upload in my file upload meta-box field (set to required)
2. Then I edit my post and upload 1 image file to the field & save the post
3. I go to the media library and delete the image I just uploaded (simulating a real case where for some reason the uploaded file is missing from the server or got deleted Inadvertently)
4. I go back to editing my post and obviously the file preview is gone (for now it still seems okay)
5. I click the “Set” button to upload another image file (still working okay here)
6. The if I try to update the post and save my changes with the freshly added image I get the following validation error message: “Folder Cover Photo must have exactly 1 items added.2“
7. Another issue is that if I do not try to add the image back and save the post it will update without throwing a validation error even though the file upload field is required and seems empty!So basically if for some reason the file or image gets deleted from the media Library, the post is stuck in that state as my file upload field is a required one… Only intervention in the database can unlock this
ps: not also the typo in the error message… the dot should be after ‘items’ 😉Thank you guys for looking at all this and here is a sample code to reproduce the issue:
<?php /* Title: Gallery Folders Listing Post Type: post Order: 10 */ piklist('field', array( 'type' => 'file' ,'field' => 'folder_cover_photo' ,'label' => __('Folder Cover Photo','stopping-the-world-admin') ,'description' => __('Give a taste of the folder\'s content.', 'stopping-the-world-admin') ,'help' => __('Sets the folder folder cover photo of the folder next to the folder title & description on the Gallery page.','stopping-the-world-admin') ,'options' => array( 'modal_title' => __('Set folder cover photo','stopping-the-world-admin') ,'button' => __('Set','stopping-the-world-admin') ) ,'required' => true ,'columns' => 12 ,'validate' => array( array( 'type' => 'limit', 'options' => array( 'min' => 1, 'max' => 1 ) ) ,array( 'type' => 'image' ) ) ));
-
-
AuthorPosts
- You must be logged in to reply to this topic.