Skip to content

Public API for checking form/field validity #5

Open
@chrisdpratt

Description

@chrisdpratt

Perhaps I missed it, but there doesn't seem to be a way to manually check form/field validity such as exists in jQuery Validation (form.validate(), form.valid(), etc.). The following method exists in the source:

/**
 * Returns a Promise that returns validation result for each and every inputs within the form.
 * @param formUID 
 */
private getFormValidationTask(formUID: string) {
    let formInputUIDs = this.formInputs[formUID];
    if (!formInputUIDs || formInputUIDs.length === 0) {
        return null;
    }

    let formValidators: Validator[] = [];

    for (let i = 0; i < formInputUIDs.length; i++) {
        let inputUID = formInputUIDs[i];
        formValidators.push(this.validators[inputUID]);
    }

    let tasks = formValidators.map(factory => factory());
    return Promise.all(tasks).then(result => result.every(e => e));
}

However, it's private and seems to only support automatic validation on submit. In certain scenarios is necessary to handle the submit event manually and check the form validity before proceeding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions