Hi,
I would like to validate the field which is a manual year input. The rule is that the value must be between a 1 year minus and plus 10 years from the current year. I would like to use the WebMaker validation - yellow triangles instead of the JS popup alert. Any suggestions please?
Regards
Kat
I would like to validate the field which is a manual year input. The rule is that the value must be between a 1 year minus and plus 10 years from the current year. I would like to use the WebMaker validation - yellow triangles instead of the JS popup alert. Any suggestions please?
Regards
Kat
RE: Date validation
It should be relatively straight forward to add this type of custom validation to your project.
The easiest way would be to add a Raise Field Error action to the start of the events against the button that is validating or submitting the data. This would be to raise the error about an invalid year against the relevant field.
To make sure that the error is only raised when the entered year is invalid, add a condition to this action. In this case I would use the 'Call Script Function' condition check, and use a function like the following:
/** * Validates the entered year, and returns whether or not it is invalid. * @return boolean true if field value invalid, false if it is ok. */ function isYearInvalid() { var enteredValue = Number(hyf.util.getFieldValue('year')); var currentYear = Number((new Date()).getFullYear()); if ((enteredValue < (currentYear - 1)) || (enteredValue > (currentYear + 10))) { //is invalid return true; } else { //is ok return false; } }
You would need to place this in an external script file used by your page, and it would need to be adjusted accordingly based on your field name etc.
If you are using 'as you type' validation as well, then you would also need to add this processing to the 'onkeyup' event for the actual control. In this case you would also want to add an additional validation condition to make sure the field is otherwise ok before triggering your custom checks. (Use a Group Validates condition check, and enter a group name of '<field>_container')
Hopefully this will get you the behaviour your require.
If you are using an older WebMaker version that doesn't have these options, or need to handle more complex requirements, then these additional forum posts may be useful:
How do I add my own custom validation checks in addition to built in functionality?
How do I customize the client side validation messages displayed on a page?
I hope this helps.
Regards,
Gerard
RE: Date validation
RE: Date validation
I+?+?+?m sorry you are having issues with this type of custom validation.
Are you able to provide some more details on exactly what validation you are trying to achieve, and the problems you are having with this approach?
It would also be useful to know which WebMaker version you are using.
Hopefully with some more details we will be able to get it working for you.
Regards,
Gerard
i am having the same issues
Hi AntoineAuton,
I+?+?+?m sorry you are having issues with date validation in your project.
Are you able to provide some more details on exactly what you are trying to do, and the errors you are getting in Chrome?
If you can provide some more information, along with confirming the version of WebMaker you are using, we can try and get your issue resolved.
Regards,
Gerard