I'm leveraging aurelia-validation for my app. What I would like to do is reset the form to empty values after a successful submission.
Here's my view class:
@inject(Validation)
export class Inquire {
@ensure(isName)
firstName = '';
@ensure(isName)
lastName = '';
. . .
constructor(validation) {
this.validation = validation.on(this);
};
sendInquiry() {
this.validation.validate()
.then(() => {
// make API call here, which works
// reset fields
this.firstName = '';
. . .
}).catch((validationResult) => {
console.log(validationResult);
});
};
};
If I set the firstName, lastName and other fields back to empty strings, the form validation is re-triggered. How can I prevent this from happening?
It seems like you should be able to call .clear() or .destroy() on the ValidationGroup as referenced here in the source code, but that isn't working for me.
this.validation.clear()after clearing out the fields is working fine for me... what do you mean on "isn't working for me" ? You see the validation errors or an error in the console? - nemesv.clear()after setting the fields back to their default values is working. Weird! - Brandon.clear()should be part of the documentation and examples. - Brandon