Class Form<Custom>

Type Parameters

  • Custom = any

Constructors

Methods

  • Do a final round of validation and get the validated answers.

    This method will not update render instructions. It is more for when you need to make sure that the form is really clean and get the final validated answers for further usage, e.g. calling API, store into database, etc.

    Returns Promise<false | Answers>

    validated answer or false if form is not clean

  • Clear answers of the entire form.

    Parameters

    Returns void

  • Clear answer of a question.

    Parameters

    Returns void

  • Clear answers of the entire group.

    Parameters

    Returns void

  • Get current answer of a question. The answer is unvalidated.

    Parameters

    • questionId: string

      question id

    Returns any

    current answer

  • Get current answers. The answers are unvalidated.

    You can persist it and use it with [[importAnswers]] method to restore the answers later.

    Returns Answers

    current answers

  • Get error of a question.

    If the question hasn't gone through validation, it will not have error, even if its answer is currently invalid.

    Parameters

    • questionId: string

      question id

    Returns any

    error

  • Get errors.

    Questions which didn't go through validation will not have errors, even if their answers are currently invalid.

    You can use [[validate]] method to validate all answers in the form.

    Returns Errors

    errors

  • Get validated answer of a question.

    If the question is disabled or it's answer is not valid, it's answer will be set to undefined.

    Parameters

    • questionId: string

      question id

    Returns any

    validated answer

  • Get validated answers.

    If a question is disabled or it's answer is not valid, it's answer will be set to undefined.

    You can persist it and use it with [[importAnswers]] method to restore the answers later.

    Returns Answers

    validated answers

  • Import answers to the form.

    Parameters

    Returns void

  • Check whether form is clean.

    Form will always be clean if it didn't go through any validation, even if there are invalid answers in the form.

    You can use [[validate]] method to validate all answers in the form.

    Returns boolean

    whether form is clean

  • Check whether form is currently being validated.

    The result might be true if you have async validator and the validation is not completed yet.

    Returns boolean

    whether form is current being validated

  • Reset answers of the entire form to default answers.

    Parameters

    Returns void

  • Reset answer of a question to default answer.

    Parameters

    Returns void

  • Reset answers of the entire group to default answers.

    Parameters

    Returns void

  • Select invididual choice.

    This method can be used by questions with choice or choices as [[type]] only.

    Parameters

    • choiceId: string

      choice id

    • selected: boolean

      selected/unselected

    • Optionaloptions: UpdateAnswerOptions

      options

    Returns void

  • Set answer of a question.

    Parameters

    Returns void

  • Set answer of a question with any as [[type]].

    Parameters

    Returns void

  • Set answer of a question with choice as [[type]].

    Parameters

    • questionId: string

      question id

    • value: any

      choice's value

    • Optionaloptions: UpdateAnswerOptions

      options

    Returns void

  • Set answers of a question with choices as [[type]].

    Parameters

    • questionId: string

      question id

    • values: any[]

      choices' values

    • Optionaloptions: UpdateAnswerOptions

      options

    Returns void

  • Parameters

    Returns void

  • Parameters

    Returns void

  • Validate the entire form.

    Returns void

    whether form is clean

  • Validate configs.

    The following validations will be conducted:

    • Form is not without any groups or questions
    • No duplicated ids within the form
    • No groups without questions
    • No questions with choice or choices as type without choices
    • No duplicated choice values within a question
    • No circular choices' onSelected configs

    Put strict as true to validate the following:

    • No unrecognized ids in choices' onSelected configs

    Parameters

    • configs: Configs

      configs

    • strict: boolean = false

      strict

    Returns ConfigsValidationResult

    validation result