Hi,
How can I limit the max total count of characters or lines(preferable) in a multi line field? I found some older tickets and was doubting if they were up to date enough.
Thanks
Marco
Hi Marco,
I think it is possible via Javascript. May I have a page on your website with the multi-select so I can work on that to be able to see if I can provide a solution?
Thanks.
Hi Christopher,
Thanks for your support! The form is in an user account so you have to login. I can send you some credentials. Please make the next message private.
Cheers
Marco
Hi Marco,
You can set the next reply as private and provide the login info and the URl that the form is there to check.
Thanks.
Hi Marco,
Thanks, I checked the video but unfortunately I could not enter the website as the password is not working.
Would you please double check with the info?
Hi Marco,
Thank you, the password worked.
Please add the jQuery code below:
jQuery.noConflict();
(function($) {
$(document).ready(function() {
var maxLines = 2;
$('textarea').on('input', function() {
var textarea = $(this);
var lines = textarea.val().split('\n');
if (lines.length > maxLines) {
textarea.val(lines.slice(0, maxLines).join('\n'));
}
});
});
})(jQuery);
Feel free to change "var maxLines = 2;" to whatever line number limitation you like.
The code above will limit the number of lines allowed to add content.
Thanks.
nOw my client is telling me that some fields need 10 lines and others need 5 lines. Is this also possible?
Hi Marco,
In the code there is a selector of the text areas:
You need to find a way to add some sort of class or ID to differentiate between the textareas and use one number for one and another number for the other one.
So if you have an HTML class added to the textarea like this:
textarea1
textarea2
Then you can have a code like this:
jQuery.noConflict();
(function($) {
$(document).ready(function() {
var maxLines1 = 2;
var maxlines2 = 5
$('.textarea1').on('input', function() {
var textarea = $(this);
var lines = textarea.val().split('\n');
if (lines.length > maxLines1) {
textarea.val(lines.slice(0, maxLines1).join('\n'));
}
});
$('.textarea2').on('input', function() {
var textarea = $(this);
var lines = textarea.val().split('\n');
if (lines.length > maxLines2) {
textarea.val(lines.slice(0, maxLines2).join('\n'));
}
});
});
})(jQuery);
Please consider that this will be considered as a custom development and we will not be able to fine-tune code for desire of your customer. If needed you are welcomed to hire a developer:
https://toolset.com/contractors/
Thank you.