javascript - 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)(& '-]+" >
<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.
解决方案
推荐阅读
- tikz - 在 tikz 中绘制辅助线
- r - 为 R 包中示例中使用的数据集生成文档
- python - 警告:“pysqlite3”的旧版轮子没有创建文件。- 我如何构建一个非传统版本的轮子?
- android - setOnClickListener 不适用于 Kotlin 中的图像滑块
- rust - 如何使用 Rocket Web 框架代理/转发数据?
- laravel - 为本地 laravel REST API 使用 http://192.168 地址
- android - 强制 Android Studio 始终为 Gradle 使用自己的 JRE
- javascript - javascript中未知的导入路径格式
- javascript - 在内部执行 XSS当 >< 被过滤并且无法使用 '" 进行转义时
- django - django social 登录后不返回用户