What I am trying to do:
I am trying to limit the number of characters that a user may input in the field named 'description' in a user form.
I have a few jQuery lines that do the job for a multi-line custom field in a CRED form, which are:
jQuery(document).ready(function ds($) {
$('textarea[name="post_excerpt"]').attr('maxlength',160);
});
( function ds( $ ) {
$( document ).ready( function ds(){
// insert div to display char count
$('textarea[name="post_excerpt"]').after("<div class='char-name'>Caractere rămase:</div><div class='char-count-s'>160</div>");
// listen for keyup and update the count
$('textarea[name="post_excerpt"]').keyup( function(){
var chars_desc_scurta = 160 - $('textarea[name="post_excerpt"]').val().length;
$('.char-count-s').html( chars_desc_scurta );
});
});
})( jQuery );
The above code works for the post excerpt and some other custom text fields I have there. Here, I need for the "description" field, which is a built-in WordPress field, it seems. I should replace 'textarea' with what? --this is in fact my main question.
This is custom code that Toolset Supporters cannot provide.
We'd have to refer you to certified contractors here https://toolset.com/contractors/
This is because Toolset doesn't offer any counting character feature. You could suggest such a feature here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Also, the solution doesn't implement Toolset API, which means the Toolset Support wouldn't be empowered to provide a complete code solution on this case.
To know what you need to address in the HTML (what you need to replace with "textarea") you'd have to analyse that field and accordingly seethrough the code and update the JS code.
In Toolset forms, there is however no default user field of name "Description", so I am not able to pinpoint which you mean, so I could have a look and eventually suggest the Name it uses, which is what you need to address the correct textarea[] or input.
Maybe you mean "Biographical info"?
That is a native WordPress user input - but it uses a Rich Editor, not a simple textarea.
Can you let me know which default WordPress "Description" Field you mean? If above, then that's not a text input, it's a Rich Editor, which doesn't output only one HTML tag, it is composed of several, rendered in an iframe.
Hello Breda and thank you for your answer.
Indeed, it is the "Biographical info" field, native to WordPress, which contains a Rich Text Editor. I thought it is possible to limit the number of characters inside, in a user form, as well, like I have managed to do with custom text fields in CRED forms...
In case I do not find a solution to the problem posted above, it is not crucial, the workaround would be to define a custom user field (of the type 'textarea') and apply to it the approach mentioned above, which works flawlessly. And use this field instead of the Biographical info whenever necessary.
I understand, but it is unrelated to Toolset.
The core issue is that you really shouldn't limit the length on rich text editors. HTML is generated on the fly by the rich text editor so you can't really limit what is being inputted.
You could technically constrain the length of the output HTML, but doing so would likely result in malformed HTML that wouldn't run/render correctly.
This might not seem what you want, but as you mention, it's better falling back to a simple input, that can't hold HTML so far, or shouldn't, so you can safely apply a restriction.
My issue is resolved now. Thank you!