我試圖將aurelia-dialog與aurelia-validation一起使用。事情是當我第一次打開彈出窗口並觸發驗證時,我得到一個正確的錯誤。每當我該事件後重新打開彈出窗口中,我得到了相同的驗證重複兩次,三次,等Aurelia對話框重複驗證
這是彈出
import { inject } from 'aurelia-framework';
import { DialogController } from 'aurelia-dialog';
import { ValidationController, ValidationRules } from 'aurelia-validation';
import { MaterializeFormValidationRenderer } from './../resources/elements/materialize-form-validation-renderer';
@inject(DialogController, ValidationController)
export class AddProject {
rules = ValidationRules
.ensure('name')
.required()
.withMessage('Please enter a name for your project.')
.rules;
constructor(dialogController, validationController) {
this.name = '';
this.project = null;
this.dialogController = dialogController;
this.validationController = validationController;
this.validationController.addRenderer(new MaterializeFormValidationRenderer());
}
activate(project) {
this.project = project;
}
detached() {
this.validationController.reset();
}
validateModel() {
return new Promise((resolve, reject) => {
this.validationController.validate().then(v => {
resolve(v.valid);
});
}, function (error) {
reject(error);
});
}
validateProject(e) {
this.validateModel().then(valid => {
if (valid) {
this.project.name = this.name;
this.name = '';
//this.validationController.reset();
this.dialogController.ok(this.project);
}
});
}
cancel(e) {
this.name = '';
//this.validationController.reset();
this.dialogController.cancel();
}
}
我打電話彈出從dialogService
視圖模型import { inject } from 'aurelia-framework';
import { DialogService } from 'aurelia-dialog';
import { AddProject } from './add-project';
import { Project } from './project';
@inject(DialogService)
export class ListProjects {
constructor(dialogService) {
this.dialogService = dialogService;
}
createProject() {
var project = new Project();
this.dialogService.open({ viewModel: AddProject, model: project, lock: false }).whenClosed(response => {
if (!response.wasCancelled) {
console.log('good - ', response.output);
}
});
}
}
任何想法如何重置驗證?我試着用這個.dialogController.cancel(),但它沒有工作。