ryanelian / aspnet-validation

Enables ASP.NET MVC client-side validation without jQuery!
MIT License
40 stars 13 forks source link

Public API for checking form/field validity #5

Open chrisdpratt opened 5 years ago

chrisdpratt commented 5 years ago

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.

ryanelian commented 5 years ago

Makes sense, sure.

I'll look into it next week (or two).

ryanelian commented 5 years ago

Hello,

I apologize for the very late delay. I have not found time to add your feature request due to an upcoming once-in-a-lifetime personal event.

I will be gone for another 4 weeks. I'll try to find time to add the feature after that.

chrisdpratt commented 5 years ago

No worries. I have a workaround. It just requires persisting the validator in a global, which is kind of icky. I appreciate the effort.