Problem:
Customer would like to set a minimum character limit on the search box - so for example you have to enter at least 10 characters before the search will work.
Solution:
To implement the feature of disabling the submit button until there are more than 10 characters in the search box, please add and customize the following JavaScript code in your CRED form's JS box:
jQuery(document).ready(function($) { // Reference to the search field and submit button var $searchField = $('input[name="wpv_post_search"]'); var $submitButton = $('input[name="wpv_filter_submit"]'); // Initially disable the submit button $submitButton.prop('disabled', true); // Event handler for keyup on the search field $searchField.on('keyup', function() { var minLength = 10; var currentLength = $(this).val().length; // Enable or disable the submit button based on the character count if(currentLength >= minLength) { $submitButton.prop('disabled', false); } else { $submitButton.prop('disabled', true); } }); });
In the code above:
- The search field is referenced by its name, wpv_post_search.
- The submit button is referenced by its name, wpv_filter_submit.
- The script initially disables the submit button.
- It enables the button only when the character count in the search field is 10 or more.
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 |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Sao_Paulo (GMT-03:00)
This topic contains 1 reply, has 2 voices.
Last updated by 11 months, 2 weeks ago.
Assisted by: Mateus Getulio.