Validation

Ensure data integrity with validation rules

Validation Guide

Learn how to implement validation rules to ensure data quality and integrity in your Appivo applications.

Validation Overview

Appivo provides validation at multiple levels:

LevelWhen It RunsPurpose
AttributeOn model saveEnsure field values are valid
WidgetOn user inputImmediate feedback
FormOn submitValidate complete form
Business RuleIn actionsCustom business logic

Attribute Validation

Built-in Validations

Configure validations when defining model attributes:

ValidationDescriptionApplies To
RequiredMust have a valueAll types
UniqueNo duplicatesAll types
Min LengthMinimum charactersText, Long Text
Max LengthMaximum charactersText, Long Text
Min ValueMinimum numberInteger, Decimal
Max ValueMaximum numberInteger, Decimal
PatternRegex matchingText types

Validation Examples

Required Email

Attribute: email
Type: Email
Validations:
  - Required: true
  - Unique: true

Constrained Number

Attribute: quantity
Type: Integer
Validations:
  - Required: true
  - Min Value: 1
  - Max Value: 1000

Pattern Matching

Attribute: product_code
Type: Text
Validations:
  - Required: true
  - Pattern: ^[A-Z]{3}-[0-9]{4}$
  - Error Message: "Must be format ABC-1234"

Widget Validation

Input Widget Validation

Configure validation on input widgets:

PropertyDescription
requiredField is mandatory
minLengthMinimum input length
maxLengthMaximum input length
patternRegex pattern
errorMessageCustom error text

Real-Time Feedback

Widgets provide immediate validation feedback:

  • Red border on invalid input
  • Error message displayed below
  • Icon indicating status
  • Tooltip with details

Validation Timing

SettingBehavior
On BlurValidate when field loses focus
On ChangeValidate on every keystroke
On SubmitValidate only when form submits

Form Validation

Complete Form Validation

When a form is submitted:

  1. All required fields checked
  2. Format validations applied
  3. Cross-field validations run
  4. Business rules executed
  5. Errors collected and displayed

Error Display

Options for showing validation errors:

StyleDescription
InlineError below each field
SummaryAll errors at top
BothInline and summary
ToastNotification popup

Handling Validation Errors

Best practices for error handling:

  1. Show clear, specific error messages
  2. Highlight the invalid field
  3. Focus on first error field
  4. Don't clear valid data
  5. Allow correction and retry

Cross-Field Validation

Comparing Fields

Validate one field against another:

Password Confirmation

Attribute: confirm_password
Validation:
  - Must equal: password
  - Error: "Passwords must match"

Date Range

Attribute: end_date
Validation:
  - Must be after: start_date
  - Error: "End date must be after start date"

Conditional Validation

Make validation depend on other values:

Attribute: business_id
Validation:
  - Required if: customer_type equals "Business"
  - Error: "Business ID required for business customers"

Business Rule Validation

Validation in Actions

Add custom validation in SCRIPT actions:

exports.execute = async function(context, params) {
    const data = params.record;

    // Custom validation
    if (data.quantity > data.stock_available) {
        return {
            success: false,
            error: 'Quantity exceeds available stock'
        };
    }

    if (data.discount > 50 && !params.user.hasRole('Manager')) {
        return {
            success: false,
            error: 'Discounts over 50% require manager approval'
        };
    }

    return { success: true };
};

Async Validation

Validate against external data:

// Check if customer has credit
const customer = await context.getRecord('Customer', data.customer_id);
if (data.order_total > customer.credit_limit) {
    return {
        success: false,
        error: 'Order exceeds customer credit limit'
    };
}

Error Messages

Writing Good Error Messages

BadGood
"Invalid""Email must be a valid address"
"Error""Please enter a quantity between 1 and 100"
"Required""Customer name is required"
"Wrong format""Phone must be in format (123) 456-7890"

Localized Messages

Support multiple languages:

Validation: Required
Messages:
  en: "This field is required"
  sv: "Detta fält är obligatoriskt"
  de: "Dieses Feld ist erforderlich"

Common Validation Patterns

Email Validation

Type: Email
Validations:
  - Required: true
  - Unique: true
  - Pattern: ^[^\s@]+@[^\s@]+\.[^\s@]+$

Phone Validation

Type: Phone
Validations:
  - Pattern: ^\+?[0-9\s-]{10,}$
  - Error: "Please enter a valid phone number"

URL Validation

Type: URL
Validations:
  - Pattern: ^https?://[^\s]+$
  - Error: "Please enter a valid URL starting with http:// or https://"

Password Strength

Attribute: password
Validations:
  - Min Length: 8
  - Pattern: (?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])
  - Error: "Password must include uppercase, lowercase, and numbers"

Best Practices

Validation Design

  1. Validate early - Catch errors as soon as possible
  2. Be specific - Tell users exactly what's wrong
  3. Be helpful - Explain how to fix the error
  4. Be consistent - Use same patterns throughout
  5. Don't over-validate - Only validate what matters

User Experience

  1. Don't prevent typing
  2. Show validation status visually
  3. Allow form submission to see all errors
  4. Preserve valid input on errors
  5. Make corrections easy

Performance

  1. Debounce onChange validation
  2. Avoid expensive async validation on keystroke
  3. Cache validation results when appropriate
  4. Batch multiple validations

Next Steps