If there are two related fields, a validation rule can be set to validate the value of one field according to the other field. You can achieve this in two ways:
-
Through assignment: changing field A assigns a value to field B.
-
If field B has some validation error, and changing A assigns a valid value to B, B's validation error should be removed.
-
However, if changing A assigns some invalid value to B, field B won't automatically display the validation error. The error will be displayed if field B is on focus and then on blur or a button is clicked to trigger the field validation.
-
-
Through cross-field validation: changing field A affects the validation of field B.
General
Changing the value of one field assigns a value to another field.
Status
Release Available |
Status |
Framework Name |
---|---|---|
3.2 |
Current |
MUI and Mint |
Example 13. Code JSON
"generalHandlers": { "fieldChange": { "genesis__Residual_Amount__c, genesis__Payment_Frequency__c": { "assignments": [{ "field": "$this.attr(genesis__Interest_Rate__c);", "value": "$ext.calculateInterestRate", "arguments": [ "$this.attr(genesis__Residual_Amount__c);", "$this.attr(genesis__Payment_Frequency__c);" ] }, { "field": "$this.attr(genesis__Payment_Amount_Per_Period__c);", "value": "$ext.calculateMonthlyPayment", "arguments": [ "$this.attr(genesis__Residual_Amount__c);", "$this.attr(genesis__Payment_Frequency__c);" ] }] }}}
Example 14. Code JSON
<script type="text/javascript"> const portalext = {}; portalext.calculateInterestRate = (amount, term) => { ... }; portalext.calculateMonthlyPayment = (amount, term) => { ... }; </script>
-
A field (minAmount) may have a relatedFields entry, which is a list of field names (e.g, [loanAmount]) in the current actor. When the value of the field (minAmount) is updated and validated, the related fields are validated automatically.
-
A field (loanAmount) may have a validation entry, which has
-
condition: if the condition is evaluated true, check the validation rule.
-
rule: if the rule is evaluated false, the message is displayed.
-
message
-
Release Available |
Status |
Framework Name |
---|---|---|
3.2 |
Current |
MUI and Mint |
Example 15. Code JSON
"fields": [ { "id": "74a8", "fieldName": "minAmount", "fieldUi": { "fieldType": "currency", "label": "Minimum Amount", "required": true, "relatedFields": [ "loanAmount" ], "format": { "options": { "numeral": true, "numeralThousandsGroupStyle": "thousand" }}}},
Example 16. Code JSON
{ "id": "ea6f", "fieldName": "loanAmount", "fieldUi": { "fieldType": "currency", "label": "Loan Amount", "required": true, "validation": [{ "rule": "$this.attr(loanAmount); >= $this.attr(minAmount);", "condition": "$this.attr(minAmount); != undefined and $this.attr(loanAmount); != undefined", "message": "Loan amount cannot be less than $this.attr(minAmount, currency);." }], "format": { "options": { "numeral": true, "numeralThousandsGroupStyle": "thousand" }}}}]
Example 17. Code JSON
{ "id": "4782", "fieldName": "newPassword", "fieldUi": { "fieldType": "string", "label": "Password", "required": true, "secure": true, "relatedFields": [ "confirmedPassword" ], "messages": { "requiredErrorText": "Password is required." } } }
Example 18. Code JSON
{ "id": "8f43", "fieldName": "confirmedPassword", "fieldUi": { "fieldType": "string", "label": "Confirmed Password", "required": true, "secure": true, "validation": [{ "rule": "$this.attr(newPassword); == $this.attr(confirmedPassword);", "condition": "$this.attr(newPassword); != undefined and $this.attr(confirmedPassword); != undefined", "message": "Password and confirmed password are not same." }], "messages": { "requiredErrorText": "Confirmed password is required." }}}]