LT-67: Re-validating fields on change only if the form validation has already been called

This commit is contained in:
Bruno Alves de Faria 2016-09-09 08:50:53 -03:00
parent c6690781f8
commit 92728c4100
2 changed files with 11 additions and 2 deletions

View File

@ -17,6 +17,9 @@ OHIF.mixins.form = new OHIF.Mixin({
// Set the form identifier flag
component.isForm = true;
// Set the form validated flag
component.isValidatedAlready = false;
component.validationObserver = new Tracker.Dependency();
// Reset the pathKey
@ -34,6 +37,9 @@ OHIF.mixins.form = new OHIF.Mixin({
// Call the original validation function
validateSelf();
// Change the form validated flag to true
component.isValidatedAlready = true;
// Focus the first error field if some validation failed
if (component.schema && component.schema._invalidKeys.length) {
instance.$('.state-error :input:first').focus();

View File

@ -235,8 +235,11 @@ OHIF.mixins.formItem = new OHIF.Mixin({
// Enable reactivity by changing a Tracker.Dependency observer
component.changeObserver.changed();
// Revalidate the component
component.validate();
const form = component.getForm();
if (form && form.isValidatedAlready) {
// Revalidate the component if form is already validated
component.validate();
}
}
},