This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix double-render issues with validation-state mixin
- Loading branch information
1 parent
6d4b318
commit faeefae
Showing
4 changed files
with
68 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
import Mixin from 'ember-metal/mixin'; | ||
import computed from 'ember-computed'; | ||
import {isEmpty} from 'ember-utils'; | ||
import {A as emberA} from 'ember-array/utils'; | ||
import observer from 'ember-metal/observer'; | ||
import run from 'ember-runloop'; | ||
|
||
export default Mixin.create({ | ||
|
||
errors: null, | ||
property: '', | ||
hasValidated: emberA(), | ||
|
||
hasError: computed('errors.[]', 'property', 'hasValidated.[]', function () { | ||
hasError: false, | ||
|
||
setHasError() { | ||
let property = this.get('property'); | ||
let errors = this.get('errors'); | ||
let hasValidated = this.get('hasValidated'); | ||
|
||
// if we aren't looking at a specific property we always want an error class | ||
if (!property && !isEmpty(errors)) { | ||
return true; | ||
if (!property && errors && !errors.get('isEmpty')) { | ||
this.set('hasError', true); | ||
return; | ||
} | ||
|
||
// If we haven't yet validated this field, there is no validation class needed | ||
if (!hasValidated || !hasValidated.includes(property)) { | ||
return false; | ||
this.set('hasError', false); | ||
return; | ||
} | ||
|
||
if (errors) { | ||
return errors.get(property); | ||
if (errors && !isEmpty(errors.errorsFor(property))) { | ||
this.set('hasError', true); | ||
return; | ||
} | ||
|
||
return false; | ||
}) | ||
this.set('hasError', false); | ||
}, | ||
|
||
hasErrorObserver: observer('errors.[]', 'property', 'hasValidated.[]', function () { | ||
run.once(this, 'setHasError'); | ||
// this.setHasError(); | ||
}).on('init') | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters