1- import { notEmpty } from '@ember/object/computed' ;
2- import { A } from '@ember/array' ;
3- import { isPresent , typeOf } from '@ember/utils' ;
4- import { computed , get } from '@ember/object' ;
5- import Component from '@ember/component' ;
6- import layout from '../templates/components/twbs-errors-alert' ;
1+ import { A } from "@ember/array" ;
2+ import Component from "@ember/component" ;
3+ import { computed , get } from "@ember/object" ;
4+ import { notEmpty } from "@ember/object/computed" ;
5+ import { isPresent , typeOf } from "@ember/utils" ;
6+
7+ import layout from "../templates/components/twbs-errors-alert" ;
78
89export default Component . extend ( {
9- attributeBindings : [ ' role' ] ,
10- classNames : [ ' alert' ] ,
10+ attributeBindings : [ " role" ] ,
11+ classNames : [ " alert" ] ,
1112 /**
1213 * Prepare a copy of the errors that include/exclude only the fields specified or returns all the errors.
1314 */
14- errors :
computed ( '_excludesArray.[]' , '_includesArray.[]' , '[email protected] ' , /*'model.errors.[]', 'model.errors.length', */ function ( ) { 15- const excludedFields = this . get ( '_excludesArray' ) ;
16- if ( isPresent ( excludedFields ) ) {
17- const filteredErrors = A ( ) ;
18- if ( isPresent ( this . get ( 'model.errors' ) ) ) {
19- this . get ( 'model.errors' ) . forEach ( ( error ) => {
20- if ( ! excludedFields . includes ( get ( error , 'attribute' ) ) ) {
21- filteredErrors . pushObject ( get ( error , 'message' ) ) ;
22- }
23- } ) ;
24- }
25- return filteredErrors ;
26- }
27- if ( isPresent ( this . get ( '_includesArray' ) ) ) {
28- const filteredErrors = A ( ) ;
29- const modelErrors = this . get ( 'model.errors' ) ;
30- this . get ( '_includesArray' ) . forEach ( ( field ) => {
31- if ( isPresent ( modelErrors ) ) {
32- modelErrors . forEach ( ( error ) => {
33- if ( field === get ( error , 'attribute' ) ) {
34- filteredErrors . pushObject ( get ( error , 'message' ) ) ;
15+ errors : computed (
16+ "_excludesArray.[]" ,
17+ "_includesArray.[]" ,
18+ 19+ /*'model.errors.[]', 'model.errors.length', */ function ( ) {
20+ const excludedFields = this . get ( "_excludesArray" ) ;
21+ if ( isPresent ( excludedFields ) ) {
22+ const filteredErrors = A ( ) ;
23+ if ( isPresent ( this . get ( "model.errors" ) ) ) {
24+ this . get ( "model.errors" ) . forEach ( ( error ) => {
25+ if ( ! excludedFields . includes ( get ( error , "attribute" ) ) ) {
26+ filteredErrors . pushObject ( get ( error , "message" ) ) ;
3527 }
3628 } ) ;
3729 }
38- } ) ;
39- return filteredErrors ;
30+ return filteredErrors ;
31+ }
32+ if ( isPresent ( this . get ( "_includesArray" ) ) ) {
33+ const filteredErrors = A ( ) ;
34+ const modelErrors = this . get ( "model.errors" ) ;
35+ this . get ( "_includesArray" ) . forEach ( ( field ) => {
36+ if ( isPresent ( modelErrors ) ) {
37+ modelErrors . forEach ( ( error ) => {
38+ if ( field === get ( error , "attribute" ) ) {
39+ filteredErrors . pushObject ( get ( error , "message" ) ) ;
40+ }
41+ } ) ;
42+ }
43+ } ) ;
44+ return filteredErrors ;
45+ }
46+ return this . get ( "model.errors.messages" ) ;
4047 }
41- return this . get ( 'model.errors.messages' ) ;
42- } ) ,
43- 'errorsPresent?' : notEmpty ( 'errors' ) ,
48+ ) ,
49+ "errorsPresent?" : notEmpty ( "errors" ) ,
4450 /**
4551 * The camel-cased field names to exclude from the computed errors collection. Takes precedence over `includes`.
4652 */
@@ -50,27 +56,27 @@ export default Component.extend({
5056 * is present.
5157 */
5258 includes : undefined ,
53- isVisible : notEmpty ( ' errors' ) ,
59+ isVisible : notEmpty ( " errors" ) ,
5460 layout,
5561 /**
5662 * REQUIRED.
5763 */
5864 model : undefined ,
59- role : ' alert' ,
60- _excludesArray : computed ( ' excludes' , function ( ) {
61- return this . _convertToArray ( this . get ( ' excludes' ) ) ;
65+ role : " alert" ,
66+ _excludesArray : computed ( " excludes" , function ( ) {
67+ return this . _convertToArray ( this . excludes ) ;
6268 } ) ,
63- _includesArray : computed ( ' includes' , function ( ) {
64- return this . _convertToArray ( this . get ( ' includes' ) ) ;
69+ _includesArray : computed ( " includes" , function ( ) {
70+ return this . _convertToArray ( this . includes ) ;
6571 } ) ,
6672 _convertToArray ( object ) {
67- if ( ' array' === typeOf ( object ) ) {
73+ if ( " array" === typeOf ( object ) ) {
6874 return A ( ) . pushObjects ( object ) ;
6975 }
7076 if ( isPresent ( object ) ) {
7177 // assume a String and split it on comma
72- return A ( ) . pushObjects ( String ( object ) . split ( ',' ) ) ;
78+ return A ( ) . pushObjects ( String ( object ) . split ( "," ) ) ;
7379 }
7480 return A ( ) ;
75- }
81+ } ,
7682} ) ;
0 commit comments