Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow limiting the number of file uploads per field #1723

Merged
merged 8 commits into from
May 8, 2019

Conversation

jom
Copy link
Member

@jom jom commented Apr 26, 2019

Fixes #516

Changes proposed in this Pull Request:

  • Allows custom multiple file fields to be added with enforced limits on the number of files that can be uploaded.
  • Updates assets/js/jquery-fileupload/jquery.fileupload.js and assets/js/jquery-fileupload/jquery.iframe-transport.js to their newest versions.

To Do

  • Enforce limit in backend.
  • Check in other browsers (Not tested: IE/Edge)

Testing instructions:

Snippet to use/adjust:

add_filter( 'submit_job_form_fields', function( $fields ) {
  $fields['job']['job_files'] = [
	'label'              => __( 'Job Files', 'wp-job-manager' ),
	'type'               => 'file',
	'required'           => false,
	'placeholder'        => '',
	'priority'           => 6,
	'ajax'               => false,
	'multiple'           => true,
	'file_limit'	     => 2,
	// 'file_limit_message' => 'You can only upload %d FILES, please and thank you',
  ];
  
  return $fields;
} );
  • With this snippet, try validation with ajax enabled and disabled. Already uploaded files count toward limit and removing them should allow for more files to be uploaded.

Note: 'multiple' => false will ignore file limit.

@jom
Copy link
Member Author

jom commented Apr 26, 2019

@tripflex Want to loop you in early on this one. The issue has a lot of Field Editor chatter, but haven't taken a look at what you're doing.

jom added 3 commits April 26, 2019 19:43
I would prefer to use HTML5 validation but when we disable the upload field validation is removed.
@jom jom changed the title [WIP] Allow limiting the number of file uploads Allow limiting the number of file uploads Apr 26, 2019
@jom jom changed the title Allow limiting the number of file uploads [WIP] Allow limiting the number of file uploads Apr 26, 2019
@jom jom added this to the 1.33.0 milestone Apr 26, 2019
@tripflex
Copy link
Collaborator

I don't see anything that would be a major conflict right off the top of reviewing it, but i will go through and test myself to make sure, and then i can make sure to integrate with the native handling for an upcoming release (and maybe deprecate the old handling for older versions of WPJM that people may still be using).

Targeting this for 1.33.0?

@jom
Copy link
Member Author

jom commented Apr 26, 2019

@tripflex Yup, targeting it for 1.33.0 (probably a month out). Let me know if you find anything we should add/change to core's implementation. There is some stuff I don't like about Ajax uploader's validation (window.alert), but I think we'll save that for another PR.

@jom jom changed the title [WIP] Allow limiting the number of file uploads [WIP] Allow limiting the number of file uploads per field Apr 26, 2019
@jom jom changed the title [WIP] Allow limiting the number of file uploads per field Allow limiting the number of file uploads per field Apr 29, 2019
@jom jom requested review from donnapep and alexsanford April 29, 2019 10:19
Copy link
Contributor

@alexsanford alexsanford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, works well! The client- and server-side validation both work for me. A couple comments below about JS i18n, but nothing critical.

@jom jom merged commit 3c05315 into master May 8, 2019
@jom jom deleted the add/file-upload-limit branch May 8, 2019 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limit number of Files Uploaded
3 participants