Problem: I would like to limit the number of repetitions in 4 repeating custom fields on a CRED form.
Solution: You must use custom JavaScript to limit these repeating fields on the front-end of the form. The following code works for the 4 fields mentioned here:
jQuery(window).bind("load", function(){ var maxreps = { 'wpcf-otros-nombres': 3, 'wpcf-patrono-a': 3, 'wpcf-imagenes-para-la-galeria': 6, 'wpcf-videos-incrustados': 6 }; jQuery(document).on( "click", ".js-wpt-repadd", function(e){ var $closest = jQuery(this).closest('.js-wpt-repetitive'); var isfile = $closest.find('input[type="file"]').length; var name = isfile ? $closest.find('.wpt-repetitive-field:first input[type="file"]:first').attr('data-wpt-name') : $closest.find('.wpt-repetitive-field:first input:first').attr('data-wpt-name'); // how many repetitions? if ( $closest.find('.wpt-repctl').length > maxreps[name] -1 ) { // hide button to add more jQuery(this).hide(); } }); // add click listener to trash buttons jQuery(document).on( "mouseup", ".js-wpt-repdelete", function(e){ var $closest = jQuery(e.target).closest('.js-wpt-repetitive'); $closest.find(".js-wpt-repadd").show(); }); });
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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
Ce sujet contient 10 réponses, a 2 voix.
Dernière mise à jour par Il y a 6 années et 8 mois.
Assisté par: Christian Cox.