Lavash.Form.ValidationJs (Lavash v0.3.0-rc.5)

Copy Markdown View Source

Generates JavaScript for form field validation and error checking.

Shared by both ColocatedTransformer (compile-time) and JsGenerator (runtime). Handles constraint-based validation (required, min_length, max, match, etc.) and custom error checks from extend_errors.

Summary

Functions

Generate JS for a combined form errors derive (concatenates all field error arrays).

Generate JS for a combined form validation derive (ANDs all field validations).

Generate JS for a field validation derive (returns boolean).

Functions

generate_combined_errors_js(name, form_name, field_names)

Generate JS for a combined form errors derive (concatenates all field error arrays).

generate_combined_validation_js(name, form_name, field_names)

Generate JS for a combined form validation derive (ANDs all field validations).

generate_field_errors_js(name, params_field, validation, custom_errors, ash_validations, skip_constraints, opts \\ [])

Generate JS for a field errors derive (returns array of error strings).

Options:

  • name - derive name (e.g., :checkout_name_errors)
  • params_field - the params state field
  • validation - validation spec
  • custom_errors - list of custom error specs from extend_errors
  • ash_validations - Ash validation specs with custom messages
  • skip_constraints - whether to skip constraint checks
  • opts - keyword list:
    • :expand_defrx - function to expand defrx in source strings (optional)
    • :server_errors_field - field name for server errors merge (optional)

generate_field_validation_js(name, params_field, validation, skip_constraints)

Generate JS for a field validation derive (returns boolean).

Options:

  • name - derive name (e.g., :checkout_name_valid)
  • params_field - the params state field (e.g., :checkout_params)
  • validation - validation spec from ConstraintTranspiler
  • skip_constraints - whether to skip all constraint checks