Tagged: , ,

Viewing 5 reply threads
  • Author
    Posts
    • #3963
      Gregg
      Member

      Hi 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.
    • #3966
      Steve
      Keymaster

      @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')

    • #3967
      Gregg
      Member

      @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.

    • #3968
      Steve
      Keymaster

      A 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.

    • #3971
      Gregg
      Member

      On 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.

    • #3972
      Steve
      Keymaster

      My pleasure… always happy to help. Closing ticket.

Viewing 5 reply threads
  • The topic ‘File Limit Exactly 1 Error’ is closed to new replies.