Tagged: 

Viewing 8 reply threads
  • Author
    Posts
    • #5940
      Adrian
      Member

      Hi, I’m using Piklist to provide additional profile fields for my site users and it’s fantastic, outstanding work guys!

      One slight issue is I’ve created a file upload field for the user to choose a header image for the public profile pages they have.

      Is there any way to limit this field to a single image?

      At the moment when the user edits their profile and hits the button to select the image it adds a second one instead of replacing the existing one.

      I’ve set the validation to only allow one, but it would be preferable if it could just use a single image and avoid the “allowing you to do something then telling you off” experience.

      My code:

      piklist('field', array(
      'type' => 'file'
      ,'field' => 'header_photo_id'
      ,'scope' => 'user_meta'
      ,'label' => __('Header Photo','piklist')
      ,'description' => __('Choose a photo to replace the default on your profile page.','piklist')
      ,'validate' => array(
        array(
          'type' => 'limit'
          ,'options' => array(
            'min' => 1
            ,'max' => 1
          )
          ,'message' => 'Sorry, you can only select one image for this.'
        )
      )
      ,'options' => array(
        'modal_title' => __('Choose Header Photo','piklist')
        ,'button' => __('Select','piklist')
      )
      ));

      Thanks!

    • #5941
      Marc
      Member

      @Adrian
      Try adding this to your field:

      
      ,'attributes' => array(
            'data-multiple' => false
      )
      
    • #5942
      Adrian
      Member

      No difference sorry!

    • #5943
      Marc
      Member

      Ok, I think I know.
      This works for me with piklist 0.9.9.7:
      Add
      ,’multiple’ => false

      to the options array:

      
      ,'options' => array(
        'modal_title' => __('Choose Header Photo','piklist')
        ,'button' => __('Select','piklist')
        ,'multiple' => false
      )
      

      Or At list it limits to one the selection in the Media window.
      If you click ‘Add’ again, it adds an other picture.
      So half a solution!

    • #5944
      Adrian
      Member

      No joy with that either. I should point out that I’m using the media uploader rather than the basic one – possibly not obvious just from the omissions of ‘basic’ => true in my code.

      What you’ve said would, I think, work fine with the basic uploader as it would add set the “multiple” attribute of a HTML5 input type upload to false.

    • #5945
      Marc
      Member

      Yes it works using the Media Uploader
      I pasted this code in Piklist demos, and it works. Not sure why it doesn’t for you!

      
      piklist('field', array(
        'type' => 'file'
        ,'field' => 'header_photo_id'
        ,'scope' => 'user_meta'
        ,'label' => __('Header Photo','piklist')
        ,'description' => __('Choose a photo to replace the default on your profile page.','piklist')
        ,'validate' => array(
          array(
            'type' => 'limit'
            ,'options' => array(
              'min' => 1
              ,'max' => 1
            )
            ,'message' => 'Sorry, you can only select one image for this.'
          )
        )
        ,'options' => array(
          'modal_title' => __('Choose Header Photo','piklist')
          ,'button' => __('Select','piklist')
          ,'multiple' => false // must be boolean, not string
        )
      ));
      
    • #5946
      Adrian
      Member

      Strange! Can you tell me at what point your process differs from what I have? This is how mine is working at the moment:

      – Click the “Select” button, Media Library lightbox loads
      – Click on an image, by holding shift two or more can be selected
      – With one selected, hit “Select” on the Media Library lightbox
      – Thumbnail shows on the edit profile page with check mark in the corner
      – Clicking “Select” again allows the process to be repeated but choosing another image loads a second thumbnail next to the first.

      The issue I have is that users will click “Select” to choose a new header image but it will just add a second one which won’t have any effect on the page.

    • #5948
      Marc
      Member

      The part that works for me is in the media Library Lightbox.
      You can only select one picture, even while holding shift.

      But if you click on Select again, this will add an other picture.
      So as I said before it only works half.

    • #5966
      Steve
      Keymaster

      Piklist doesn’t limit the media uploader. But when the user presses SAVE, Piklist will display a message telling the user that they can’t upload more than one file.

      There is an example of this in Piklist Demos under the Validation tab. Take a look at the “Add File(s)” field.

Viewing 8 reply threads
  • You must be logged in to reply to this topic.