Info |
---|
In this tutorial you will learn how to use advanced techniques when defining validation rules. The approach and techniques shown are valid for all type of fields, not only dates as in the tutorial. |
Excerpt Include |
---|
| Creating a simple form in Confluence with ConfiForms |
---|
| Creating a simple form in Confluence with ConfiForms |
---|
nopanel | true |
---|
|
Quite often, when having fields to keep 2 dates, you need to have some kind of a relationship between these fields.
Like, ensuring that "End Date" field is after the "Start Date" field, for example.
This validation is possible to automate in ConfiForms by using the "ConfiForms Field Definition Rules" macro and using it's "Action" selected to "Validation Rule"
Info |
---|
If you need to have 2 dates together consider using "Date Interval" field type in ConfiForms. Very useful when used in ConfiForms CalendarView |
Let's start with a simple form.
Just 2 fields, both of time date
The configuration for fields is straightforward:
Same for "endDate"
So the form looks like this on the page:
It has no validations so far... and we gonna add one:
The important bits are in the screenshot below:
Explanations:
- we set up this rule to execute on the "endDate" field
- the condition is set to be dynamic, meaning that it will get the value for "startDate" field from the current record and will compare it with the value of "endDate"
- Message is set to be "Hold on!"
- And the most important bit here is to add a validation rule when condition is met, and that is "." which will match anything.
- This means that when the condition is met, and endDate is before the starDate then run the validation rule which will match ANYTHING (as . in regular expressions matches anything). The message will be shown. When condition is not met the validation rule is not executed... and the message will not be shown (the record will be valid)
That's it. It is true that it has a small trick, but here is the hint:
Info |
---|
Define a condition that when met will mean the data is not correct and add a validation rule to match everything (using dot ("."), without brackets and quotes) to fire the match and show the message to user |
Storage format (configuration) for the whole solution:
Expand |
---|
Code Block |
---|
<ac:structured-macro ac:macro-id="cd6b5bbb-c91c-4cab-aa6a-b7c903e1246e" ac:name="confiform" ac:schema-version="1">
<ac:parameter ac:name="formName">formWithDates</ac:parameter>
<ac:rich-text-body>
<p>
<ac:structured-macro ac:macro-id="2cd071cd-0ac7-4152-854b-f3b6610cbc31" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">startDate</ac:parameter>
<ac:parameter ac:name="fieldLabel">Start Date</ac:parameter>
<ac:parameter ac:name="type">date</ac:parameter>
</ac:structured-macro>
</p>
<p>
<ac:structured-macro ac:macro-id="03a9a452-574f-4e67-9f98-7e71dc5bcddb" ac:name="confiform-field-definition" ac:schema-version="1">
<ac:parameter ac:name="fieldName">endDate</ac:parameter>
<ac:parameter ac:name="fieldLabel">End Date</ac:parameter>
<ac:parameter ac:name="type">date</ac:parameter>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="004f84b4-a0af-44c6-8793-c7bb06bdd492" ac:name="confiform-entry-register" ac:schema-version="1">
<ac:parameter ac:name="atlassian-macro-output-type">INLINE</ac:parameter>
<ac:rich-text-body>
<p> </p>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:macro-id="d506bcd8-ab88-4845-81b9-7dda48fd7247" ac:name="confiform-field-definition-rules" ac:schema-version="1">
<ac:parameter ac:name="condition">endDate:<[entry.startDate]</ac:parameter>
<ac:parameter ac:name="fieldName">Hold on! End date is expected to be AFTER the start date</ac:parameter>
<ac:parameter ac:name="values">.</ac:parameter>
<ac:parameter ac:name="action">Validation rule</ac:parameter>
<ac:parameter ac:name="actionFieldName">endDate</ac:parameter>
</ac:structured-macro>
</p>
</ac:rich-text-body>
</ac:structured-macro>
|
|