Problem:
A Toolset Form includes repeating fields where the user can add additional instances of the field. Client wants to limit how many instances of the field can be added, in such a way that the same technique (with different limits) can be used on multiple fields.
Solution:
A simple solution is to use a little custom JavaScript which hides the "Add New" button once the relevant number of instances has been added.
To be able to target different fields with different limits, add a class to the div wrapping the form field, something like this, where the class 'limit-to-3' is added:
<div class="form-group limit-to-3"> <label>Owner</label> [cred_field field="owner" force_type="field" class="form-control" output="bootstrap"] </div>
You can then use custom JS like so:
jQuery(function($) { $(".limit-to-3 .js-wpt-repadd").click(function(event) { $length = this.parentNode.childNodes.length; if ($length >= 5) { $(this).hide(); } }); });
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.
Our next available supporter will start replying to tickets in about 1.16 hours from now. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 4 replies, has 2 voices.
Last updated by 5 years, 12 months ago.
Assisted by: Nigel.