In the Individual Compensation section, a custom field-level validation was implemented to make the Amount field required. This validation works correctly when clicking Save on the Individual Compensation section. However, when clicking on Continue, it still triggers the same validation error message, which is not desired.
VBS - Validate Field Values
define([], () => {
'use strict';
function runCondition(context) {
const { $fields } = context;
// Get the current Amount field value
let rawAmount = $fields.individualCompensationDetails.ValueString.$value();
// **Skip validation if no Plan is selected** (no compensation entry being added)
if ($fields.individualCompensationDetails.PlanId.$value() == null) {
return false; // No plan chosen, so don't trigger any error for Amount
}
// If Amount is empty or just whitespace, trigger the validation error (field is required)
if (!rawAmount || rawAmount.trim() === "") {
return true; // Return true to indicate validation failure (required field missing)
}
// Remove currency code (e.g., "USD") and trim spaces for numeric comparison
let cleanedAmount = rawAmount.replace("USD", "CAD", "INR", "").trim();
// If the numeric amount is less than 0, trigger a validation error (no negative amounts)
return Number(cleanedAmount) < 0;
}
return { runCondition };
});
I hope this blog post was helpful for you. If you have any questions or feedback, please leave a comment below.