Skip Navigation

[Resolved] Limit the Maximum Number of Flat Taxonomies in the Form

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 1 voice.

Last updated by willaL 8 months, 2 weeks ago.

Assisted by: Minesh.

Author
Posts
#2786837
tags.PNG

Is there a way to set an upper limit on the number of Flat Taxonomies on the form page?

#2786898

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

AS I understand - you have Toolset post form to add/edit content where you have tags taxonomy added and you want to restrict the user to add only x number of tags - is that correct?

#2786926

Yes. That's correct.

#2786944

Minesh
Supporter

Languages: English (English )

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

Well - You can use the Toolset form hook "cred_form_validate" in order to validate your form:
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

#2786948

Okay. Should the tag taxonomy be considered as repetitive fields? If not, could you provide an example? Thank you.

#2786949

Minesh
Supporter

Languages: English (English )

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

If you can share admin access details and also share the URL where on that page you added the form and you want to restrict to how many tags and I would be happy to look at and share solution with you.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2787096

Minesh
Supporter

Languages: English (English )

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

Fortunately - I'm able to find a workaround to restrict tags to 5.

For that I've added the following custom JS code and I've merged that with your existing custom JS code on your form's JS editor:
=> hidden link

jQuery(document).ready(function($){
    jQuery("textarea[name='wpcf-artworks-description']").attr("maxlength",150)
    var maxLength = 150;
  jQuery("textarea[name='wpcf-artworks-description']").keyup(function() {
    var length = jQuery(this).val().length;
    var length = maxLength-length;
    jQuery('#chars').text(length);
  
  });

  jQuery("input[name='post_title']").attr("maxlength", 30);
  
    jQuery.validator.addMethod("maxselections", function(value, element, param) {
                                var element_name = jQuery('input[name="tags"]').attr('name');
      						//	console.log(jQuery('input[name="' + element_name + '"]').val().split(",").length);
      						//	console.log(param[1]);
                                return (jQuery('input[name="' + element_name + '"]').val().split(",").length !=0 && (jQuery('input[name="' + element_name + '"]').val().split(",").length) <= (param[1]-1)); 
      
                              },"You can select maximum 5 tags.");
  
  
  
                               
    jQuery('input[name="tmp_tags"]').attr('data-wpt-validate', '{}')
        .data('wpt-validate', {
          maxselections: {
            args: {
              1: 5
            }
          }
    }); 
     

});

Now, if user add more than five tags it will popup error message and user will not be able to submit the form.

Can you please check if that help you to resolve your issue.

#2787213

Thanks!