Portlet describes how should it work:
Enter JavaScript code that returns true or false to validate the field. The following implicit variables are available.
currentFieldValue: The value being validated fieldsMap: The array of all form values indexed by name
I haven't found any documentation about this.
Anyways, I have web form that send the form input to my email, but if the last checkbox is not checked then it should give an error.
So I came up with this code, but it doesn't work:
if(currentFieldValue == false){return false;}
Anybody knows how this liferay webform portlet validation works?
Stop Tomcat
Go to APPLICATION_SERVER_ROOT_DIRECTORY/webapps/web-form-portlet/WEB-INF/classes directory
Open portlet.properties and change "validation.script.enabled" property from "false" to "true"
Start Tomcat
Add Web Form portlet to a page
On the configuration pop-up of Web Form portlet we added a Check Box type field with the validation script you wrote in the description: "if(currentFieldValue == false){return false;}" and the validation error message: "Tick the checkbox!"
Tried to send the created form without selecting the checkbox created in the previous step.
Result : "Tick the checkbox!" message appeared on the screen.
I tried it like this way but I always got the rrror You have entered invalid data. Please try again.
You have entered invalid data. Please try again.
.
So I started to change
if(currentFieldValue == false){return false;}
into
if(currentFieldValue != ""){return true;}
It seemed that the submit needs an true
may it's set automaticaly to false
.
This works with all kind of fields.
currentFieldValue
始终是一个字符串,因此对我来说正确的解决方案是将验证脚本设置如下:
return (currentFieldValue == 'true')
I followed the steps mentioned in the post of Algeron. I added the custom validation in the checkbox field and when I fill the form and click the save button, the form can't be processed. In the tomcat stdout logs I found the next error:
12:45:27,628 ERROR [http-bio-8080-exec-2][WebFormUtil:257] The following script has execution errors:
return (currentFieldValue == 'true');
missing ] in index expression (Validation Script#8)
Anyone have any ideas how I could solve it? Thanks in advance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.