首页 > 解决方案 > Clicking on next button it saves form.But once I come back to previous page and again click on same next button it shows validation error message

问题描述

 <Validations>
    <Validation type="otherCompComplete" value = "" >
        <Message>it is something else </Message>
            < /Validation>
            < Validation type = "required" value = "true" >
                <Message>Please enter a value</Message>
                    < /Validation>
                    < Validation type = "maxlength" value = "65" >
                        <Message>Common_Shared_MaximumLengthError < /Message>
                        < /Validation>
                        < Validation type = "pattern" value = "[a-zA-Z0-9)(&amp; '-]+" >
                            <Message>error < /Message>
                            < /Validation>
                            < /Validations>``

       // this method is called in ngoninit

DeliverQuestion = (field: FormFieldModel<any>) => {
    switch (field.id) {
        case 'OtherCompanyName':
            if (field.value !== null) {
                this.something = field.value;
            }
            return {
                ...field,
                onInput: ($event: IDetailedEvent) => {
                    this.updateFormValue(field, $event.details['control'].value, true);
                    this.onOtherCompanyNameChange($event.details['control'], 'OtherCompanyName');
                },
                onSelection: ($event: IDetailedEvent) => {
                    this.updateFormValue(field, $event.details['control'].value, true);
                    this.something = field.value;
                    this.onOtherInsuranceCompanyNameChange($event.details['control'], 'OtherCompanyName');
                },
                validators: [
                    ...field.validators.filter(({ type }) => type.toLowerCase() !== 'othercompcomplete'),
                    {
                        type: 'otherCompComplete',
                        useValue: (control: any) => {
                            return this.otherCompValidator(control, field.id);
                        },
                        message: field.validators.filter(({ type }) =>
                            type.toLowerCase() === 'otherCompComplete')[0].message,
                    },
                ]
            };
        default:
            return field;
    }

       // validator method

    otherCompValidator(control: any, fieldId: string): boolean {
        if (control.value && control.value.length > 3) {
            let selectFieldModel = this._formService.findField(this.Historyfo.questionGroup.questions, formField =>
                formField.id === fieldId) as AutocompleteFieldModel;
            if (selectFieldModel && selectFieldModel.answers) {
                let isValid = false;
                let value = control.value.trim().toUpperCase();
                selectFieldModel.answers.forEach(element => {
                    if (element.value.toUpperCase() === value) {
                        isValid = true;
                        this.form.controls['OtherCompanyName'].updateValueAndValidity();
                    }
                });
                return isValid;
            }
        }
    }

Clicking on next button it saves the form.But once I come back to previous page and again click on same next button it shows validation error message. This code throws the custom error which is defined in the XML. I checked that the form is correctly saving and shows the value in the UI too. But Once I click form submit it throws that error.

标签: javascriptc#angularxmluser-interface

解决方案


推荐阅读