[opencms-dev] Webform Generator Module - word count validation?
Graeme Kidd
coolkidd3 at hotmail.com
Mon Sep 12 14:27:20 CEST 2011
Yeah the quickest way to add a word count validation would be to simply add the
following regex:
(\b\w+\b.*){25,}
This would prevent a field with less than 25 words from being submitted. You
can then set the "Error Message" field to say "Please enter more
than 25 words" so that the user knows to type more words.
However if you feel you would also like some client side validation or maybe
even a handy word count tool, then I see two options.
The first would be to write your JavaScript in the form.jsp file and do some
extra DOM navigation to correctly identify the text area. The best way to do
this would be to check the current field position in the webform module e.g.
"Form field [10]" which translates to the "name" attribute
for the text area e.g. "InputField-10".
Obviously this will change if you add more fields above it but if that’s very
unlikely then this may be the quickest option.
The second option means getting stuck into some Java code to create your own
field. The best documentation I could find for this method is in some JavaDoc
comments:
http://cvs.opencms.org/viewvc.cgi/alkacon/com.alkacon.opencms.formgenerator/src/com/alkacon/opencms/formgenerator/CmsFieldFactory.java?view=markup
Basically you can create your own field class that implements A_CmsField or
simply extends the CmsTextareaField class. This will allow you the freedom to
create and customise your own field with its own HTML. You can then specify this class in a file
called "custom_form_field.properties" which can be placed here:/system/modules/com.alkacon.opencms.formgenerator/classes/With the text specified as:
FIELDS=wordcount:mysite.com.CmsWordCountField,lettercount:mysite.com.CmsLetterCountField
You
might need to restart Tomcat, but once its working you can then select
your custom field e.g. "Word Count" from the field drop down
menu.
Hope that help,
Graeme
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sitback-logo.jpg
Type: image/jpeg
Size: 8308 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20110912/fca60b30/attachment.jpg>
More information about the opencms-dev
mailing list