1- import { get as objGet , forEach , isFunction , isString , isArray , debounce , isNil } from "lodash" ;
1+ import { get as objGet , forEach , isFunction , isString , isArray , debounce , isNil , uniqueId } from "lodash" ;
22import validators from "../utils/validators" ;
3- import { slugifyFormID } from "../utils/schema" ;
43
54const convertValidator = ( validator ) => {
65 if ( isString ( validator ) ) {
@@ -37,11 +36,16 @@ export default {
3736 } ,
3837 eventBus : {
3938 type : Object
39+ } ,
40+ fieldID : {
41+ type : String
4042 }
4143 } ,
4244
4345 data ( ) {
46+ const fieldUID = uniqueId ( this . fieldID + "_" ) ;
4447 return {
48+ fieldUID,
4549 errors : [ ] ,
4650 debouncedValidateFunc : null ,
4751 debouncedFormatFunction : null
@@ -109,19 +113,21 @@ export default {
109113
110114 watch : {
111115 errors : {
112- handler : function ( errors ) {
116+ handler ( errors ) {
113117 this . $emit ( "errors-updated" , errors ) ;
114118 }
115119 }
116120 } ,
117121
118122 methods : {
119123 getValueFromOption ( field , option , defaultValue ) {
120- if ( typeof this . $parent . getValueFromOption === "function" ) {
124+ if ( isFunction ( this . $parent . getValueFromOption ) ) {
121125 return this . $parent . getValueFromOption ( field , option , defaultValue ) ;
122126 } else {
123127 // Environnement de test ?
124- if ( isNil ( field [ option ] ) ) return defaultValue ;
128+ if ( isNil ( field [ option ] ) ) {
129+ return defaultValue ;
130+ }
125131
126132 return field [ option ] ;
127133 }
@@ -142,12 +148,12 @@ export default {
142148 if ( ! isArray ( this . schema . validator ) ) {
143149 validators . push ( convertValidator ( this . schema . validator ) . bind ( this ) ) ;
144150 } else {
145- forEach ( this . schema . validator , ( validator ) => {
151+ this . schema . validator . forEach ( ( validator ) => {
146152 validators . push ( convertValidator ( validator ) . bind ( this ) ) ;
147153 } ) ;
148154 }
149155
150- forEach ( validators , ( validator ) => {
156+ validators . forEach ( ( validator ) => {
151157 if ( validateAsync ) {
152158 results . push ( validator ( this . value , this . schema , this . model ) ) ;
153159 } else {
@@ -167,7 +173,7 @@ export default {
167173
168174 let handleErrors = ( errors ) => {
169175 let fieldErrors = [ ] ;
170- forEach ( errors , ( err ) => {
176+ errors . forEach ( ( err ) => {
171177 if ( isArray ( err ) && err . length > 0 ) {
172178 fieldErrors = fieldErrors . concat ( err ) ;
173179 } else if ( isString ( err ) ) {
@@ -182,7 +188,7 @@ export default {
182188
183189 this . errors = fieldErrors ;
184190
185- this . eventBus . $emit ( "field-validated" , isValid , fieldErrors , this . _uid ) ;
191+ this . eventBus . $emit ( "field-validated" , isValid , fieldErrors , this . fieldUID ) ;
186192 return fieldErrors ;
187193 } ;
188194
@@ -265,11 +271,6 @@ export default {
265271 }
266272 } ,
267273
268- getFieldID ( schema ) {
269- const idPrefix = objGet ( this . formOptions , "fieldIdPrefix" , "" ) ;
270- return slugifyFormID ( schema , idPrefix ) ;
271- } ,
272-
273274 formatValueToField ( value ) {
274275 return value ;
275276 } ,
0 commit comments