Skip Navigation

[Resolved] How to limit the number of images per field.

This support ticket is created 5 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 3 voices.

Last updated by FelipeP5703 5 years, 3 months ago.

Assisted by: Minesh.

Author
Posts
#1351417

So apparently you don't even need that my_files_only code since Access has a setting for that. I tested it and I only see the images that user uploaded... so one thing down, two to go...

Now I still don't know how to limit the number of images per field. The code I had to limit was this below, but since the change of being able to add multiple images at once, the code does not work.

jQuery(function($) {
    $(".limit-to-6 .js-wpt-repadd").click(function(event) {
        $length = this.parentNode.childNodes.length;
        if ($length >= 6) {
            $(this).hide();
        }
    });
});

Then I added to the div like this:

<div class="form-group col-sm-6 limit-to-6">
			[cred_field field='fotos-para-anuncio' force_type='field' class='form-control' output='bootstrap']
		</div>

1) Use WordPress built-in media manager to upload/crop the images as I mentioned above: With WordPress built-in media manager user can click link "Edit Image", and crop the image manually, see screenshot: crop.JPG

I don't see an option to edit the photo, look at the screenshot. I have set properly in Access to allow Authors to edit their images. Look at the screenshot.

#1351425

Hello,

Yes, you are right, there isn't such kind of built-in feature within Toolset Forms plugin, it needs custom codes.
You can try these:
1) Change the CSS class name to field slug "fotos-para-anuncio", for example:

	<div class="form-group fotos-para-anuncio">
		<label>fotos-para-anuncio</label>
		[cred_field field='fotos-para-anuncio' force_type='field' class='form-control' output='bootstrap']
	</div>

2) modify the JS codes as below:

jQuery(document).on('cred_form_ready', function(){
    jQuery(".fotos-para-anuncio .js-wpt-repadd").click(function(event) {
        jQuerylength = jQuery('.fotos-para-anuncio .js-wpt-field-items .wpt-repctl').length;
        if (jQuerylength >= 6) {
            jQuery(this).hide();
        }
    });
});

And test again.

#1351869

It works fine if the Media Library is not checked as an option. But if you have it checked, the user can upload as many images as they want.

#1352293

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo is not available at the moment. This is Minesh here and I'll take care of this ticket. Hope this is OK.

There is no such native feature available but I think it will be a good feature to add to our plugin. Please feel free to file a new feature request using the following link:
=> https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

If user is loggedin and you want to limit the number of file uploads for user - you can use the wordpress filter: wp_handle_upload_prefilter

Please check the following links that may help you:
=> https://wordpress.stackexchange.com/questions/21084/how-can-you-limit-the-number-of-images-videos-that-can-be-uploaded-to-a-wordpr
=> hidden link

#1353087

I'm not using Media Library to upload files, thus the current code I have now is sufficient. My issue is resolved now. Thank you!