CMS String field word count

Hi community,

We would like to add a (real-time) word count to (configurable) String fields. While a user is typing inside the field, they should see how many characters the field currently contains and how many it allows max (if applicable). This is easily done in Javascript, but we’re not sure where to apply it within the CMS. Do you have any pointers where to start? References to code examples that have similar functionality are greatly appreciated.

Kind regards,
Davey Chu

I think you would have to extend or override the display plugin. That is configured in the editor:template of the namespace of the document. This would also likely break in some future update, which adds a maintenance burden to your project. You could file a feature request, possibly with a contribution of actual code, but I can’t guarantee this would be picked up or, even if it is picked up, if it would be released in a reasonable time frame for you.

Thank you for your reply Jasper.

Do I understand correctly that you imply changing the plugin.class property of a frontend:plugin node to a custom class? Is this documented anywhere?

Could you suggest any alternatives that would make it less prone to breaking with future updates? I was thinking in the direction of adding custom Javascript to the CMS (e.g. https://groups.google.com/forum/#!topic/hippo-community/gvyNP132ZT0) and add listeners to input fields with a certain class. What’s your opinion on this approach?

Kind regards,
Davey

This isn’t documented afaik since it isn’t really intended as an extension point. However, these are just wicket classes so it is entirely feasible to customize them if desired. The problem is that we may change the UI which could break your code. Or sometimes we update the wicket version. Adding JS to do this faces the same issues really.

Your best bet for future compatibility is to get this as a new feature in the product, but I doubt something like that would get high priority at this moment. However, this is your best route to get a future proof solution.