Skip Navigation

[Resolved] Setting character limit on a Single Line field.

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

Problem:

The issue here is that the user wanted to set a character limit to their backend single line custom field.

Solution:

For this to work you will need to install the plugin below.
https://wordpress.org/plugins/custom-css-js/

Secondly you will need to add a new custom JS code snippet.

Ensure that the options on the snippet are exactly the same as mine, see screenshot

Then add the following to your snippet.

jQuery(document).ready(function( $ ){
           jQuery("input[name='wpcf[linked-many]']").attr("maxlength", 4);
 
});

Now you need to replace 'linked-many' with slug of your custom field and replace the 4 with the number of characters you want to limit the field to.

This support ticket is created 5 years, 2 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
- 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 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 10 replies, has 2 voices.

Last updated by barryG-4 5 years, 2 months ago.

Assisted by: Shane.

Author
Posts
#1336757

Tell us what you are trying to do?
I wish to set a character limit in a custom type single line field.

Is there any documentation that you are following?
Yes I've gone through this and got the code but I'm unsure where to put it. I was thinking in functions.php or header.php but I don't think the code I have is complete for these locations. I am not knowledgable enough to know if I need to wrap the code in other code. https://toolset.com/forums/topic/limit-number-of-characters-or-words-in-single-line-field/

I was hoping there would be a character limited box in the Toolset custom field wizard for someone like me.

Is there a similar example that we can see?
Sorry not that I'm aware of.

What is the link to your site? It's a test site at the moment.
hidden link

The contents from the custom field is to somehow be referenced and and be added to the WP excerpt field (which currently displays just the 'webcam offline' button under the image and model name.

#1336801

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Barry,

Thank you for getting in touch.

Is this for the backend or is it for a frontend form ?

Please let me know.

Thanks,
Shane

#1336857

Hi Shane,

The custom post type field is from a CP post type group assigned to a CP type called models that administrators and editors will edit posts in. The field will be a brief description of the model showing under an image and her name in a gallery page here: hidden link so iIt needs to be character limited so the text is only on one line to make sure the gallery looks uniformed. I've only got one gallery entry for now but does this answer your question. Many thanks, Barry.

#1336861

So a short answer would be backend. Many thanks, Barry.

#1337971

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2019-09-11 at 10.28.25 AM.png

Hi Barry,

For this to work you will need to install the plugin below.
https://wordpress.org/plugins/custom-css-js/

Secondly you will need to add a new custom JS code snippet.

Ensure that the options on the snippet are exactly the same as mine, see screenshot

Then add the following to your snippet.


jQuery(document).ready(function( $ ){
	       jQuery("input[name='wpcf[linked-many]']").attr("maxlength", 4);

});

Now you need to replace 'linked-many' with slug of your custom field and replace the 4 with the number of characters you want to limit the field to.

Please let me know if this helps.
Thanks,
Shane

#1337991

Hi Shane,

Thank you very much for the information but I don't know where to add the snippet you gave me? Could you please tell me where I go to add this. Is it too header.php, functions.php or somewhere else. Apologies for not knowing.

Many thanks,
Barry.

#1337995

Hi Sahne,

Ignore that.....I can see the options now from inside the plug in.

Many thanks,
Barry.

#1338011
Screenshot 2019-09-11 at 17.31.26.png
Screenshot 2019-09-11 at 17.31.39.png

Hi Shane,

I've done as you suggested but it still lets me add more than 100 characters as you can see here.

Many thanks,
Barry.

#1338083

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Barry,

Could you try copy and pasting it exactly like this.

jQuery(document).ready(function( $ ){
           jQuery("input[name='wpcf[model-subtitle]']").attr("maxlength", 4);
 
});

Thanks,
Shane

#1338189

Hi Shane,

Thank you very much indeed. It works! I couldn't see the difference but it really works so I'm very grateful.

Many thanks,
Barry.

#1338191

My issue is resolved now. Thank you!