Define max characters in Structures (Liferay 7.1)

Jordi Martinez, modified 5 Years ago. New Member Posts: 5 Join Date: 1/24/20 Recent Posts
Hello everyone!

I'm trying to define a new template + structure to make the user able to create their own content. My goal is to let them put some text and images, and style them to be shown properly.
I want to set the maximum text for them to be able to introduce to 140 characters.
Is there a way to set it in the structure (I think this is where the solution can be ,but don't know how), template or article? Or when they're introducing data that the field got marked in some way (like a text appearing or the border of the field turning red, or something like this) if they surpass the max length.

Thank you in advance for your response!
thumbnail
Andrew Jardine, modified 5 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Jordi,
Out of the box? pretty sure this is not an option. Having said that, there is a way you COULD add this, but it's not a "super clean" solution. I would be inclined to try it though to see if it works. 1. Create a new theme-contributor plugin: https://help.liferay.com/hc/en-us/articles/360018170951-Theme-Contributor- (7.0 reference but should still work in 7.1)
2. In your contributor add the JS that is used to register the on change event for the field. You should be able to get the field name from the page where the content is created.
3. Deploy.

Now, one thing to note is that this JS will now be loaded on every page of course because it's "global in nature" and not unique to any one given theme. In this case you are trying to do this in the control panel though so, short of making your own control panel theme I think this is a necessary evil. To be clear, I've never used this technique for something like this, but I have used it for a few other outlier type scenarios and it worked emoticon