Tell us what you are trying to do?
I'm attempting to limit the number of characters that users can submit in the post content field using a CRED form.
This is the support ticket I'm referencing, but I can't get the code to work for me.
https://toolset.com/forums/topic/limiting-characters-in-field/
This is the link to the page with the CRED form on it:
hidden link
The Coaching Philosophy field is what will submit as the post content field once the user submits the form.
Below are the contents of my JS editor for this form. The relevant section of code for this ticket is everything below the comment ''Validate maximum characters in post_content field."
jQuery(document).ready(function ($) {
// Limit to selection of 5 niches in a coach listing.
var niche_limit = 5;
$('input:checkbox[name="niche[]"]').on('change', function(evt) {
if($('[name="niche[]"]:checked').length > niche_limit) {
this.checked = false;
alert("Maximum 5 niches allowed.")
}
});
});
// Validate maximum characters in post_content field
jQuery(document).ready(function ($) {
$('[name^=post_content]').attr('maxlength',280);
});
( function( $ ) {
$( document ).ready( function(){
// insert div to display char count
$('textarea[name="post_content"]').after("<div class='char-count'>0</div>");
// listen for keyup and update the count
$('textarea[name="post_content"]').keyup( function(){
var chars = $('textarea[name="post_content"]').val().length;
$('.char-count').html( chars );
});
});
})( jQuery );