Skip Navigation

[Resolved] character insertion limit

This thread is resolved. Here is a description of the problem and solution.

Problem:
I have the code to limit the number of characters,
works with all fields except the multi-line field.
Solution:
Because that is a complex field, not a single simple text line.
You can limit the number of characters in multiline field by using following jQuery code:
$(document).ready(function () {
$('.multiline-field').keypress(function (e) {
maxChars = 10;
if ($('.multiline-field').val().length >= maxChars) {
e.preventDefault();
}
});
});
Relevant Documentation:

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 13 replies, has 3 voices.

Last updated by massimoS527 6 years, 9 months ago.

Assisted by: Noman.

Author
Posts
#616699

in the CRED module (editor JS) I have this code to limit the number of characters,
works with all fields except the multi-line field "racconta". Because ?

<code
// limita lunghezza caratteri

jQuery(document).ready(function () {
------> jQuery("input[name='wpcf-racconta']").attr("maxlength", 400); <--------------
jQuery("input[name='post_title']").attr("maxlength", 30);
jQuery("input[name='wpcf-dedica']").attr("maxlength", 30);
jQuery("input[name='wpcf-dedica-seconda']").attr("maxlength", 30);
jQuery("input[name='wpcf-data-decesso']").attr("maxlength", 20);
});

[/php]

#616731

Because that is a complex field, not a single simple text line.

I assume the code also does not work on WYSIWYG Fields?

Those fields cannot be validated like this, but we have feature requests in place to allow at least a new filed type or method to count/limit amount of characters.

I added your voice to that request.

#616749

infatti è un campo multi linea .
la richiesta che tu parli, pensi sia risolta a breve ? se sì, come faccio a saperlo ?

grazie

#616775

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

You can subscribe to our blog as we announce updates and new features there:
https://toolset.com/blog/

Thank you

#616820

ok , esiste una soluzione alternativa ?
questo passaggio è fondamentale per proseguire .

grazie

#616855

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

#616953

grazie per l'aiuto che mi stai dando,

ho inserito il codice

add_shortcode('trim', 'trim_shortcode');
function trim_shortcode($atts, $content = '') {
  $content = MIO_NOME_ FIELD ($content);
  $length = (int)$atts['length'];
  if (strlen($content) > $length) {
    $content = substr($content, 0, $length) . '&hellip;';
  }
  return $content;
}

poi lo richiamo così

[trim length="50"][cred_field field='racconta' post='creatura' value='' urlparam='' class='form-control' output='bootstrap'][/trim]

non succede nulla

#617311

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

You can limit the number of characters in multiline field by using following jQuery code:

$(document).ready(function () {
	$('.multiline-field').keypress(function (e) {
		maxChars = 10;
		if ($('.multiline-field').val().length >= maxChars) {
			e.preventDefault();
		}
	});
});

I have set limit to 10 characters, You can change that number according to your need.
You can add above js code in Js editor and update ‘.multiline-field’ to your multiline field selector.

Thank you

#617404

it does not work, it does not limit me anything

$(document).ready(function () {
    $('NAME-FIELD').keypress(function (e) {
        maxChars = 10;
        if ($('NAME-FIELD').val().length >= maxChars) {
            e.preventDefault();
        }
    });
});
#617422

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

For further debug, provide temporary access WP-Admin Login and FTP login info to your site. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please provide backend-end and front-end link where we can see the issue.

Thank you

#617442

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

Login info is working but issue is in my user role. Can you please update my user role to Administrator so that i can fix the issue.

Please kindly open a new ticket for each issue. This will help other users with similar problems to find solutions when searching the forum.
https://toolset.com/toolset-support-policy/

Thank you

#617624

Ruolo modificato

#617668

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

I have deactivated WP Fastest Cache plugin and added following code:.

$(document).ready(function () {
	$('.multiline-field').keypress(function (e) {
		maxChars = 10;
		if ($('.multiline-field').val().length >= maxChars) {
			e.preventDefault();
		}
	});
});

in JS editor and added ‘multiline-field’ class to multi line field.
Now it’s working perfectly fine. Can you please check and confirm?

Here is page link:
hidden link

Thank you

#617808

you are a genius !!!!

How can I become like you?
is there a Toolset guide?

solution:

codice JS:

$(document).ready(function () {
    $('.multiline-field').keypress(function (e) {
        maxChars = 10;
        if ($('.multiline-field').val().length >= maxChars) {
            e.preventDefault();
        }
    });
});

module CRED:

[cred_field field='racconta' post='creatura' value='' urlparam='' class='multiline-field form-control' output='bootstrap']