@@ -53,7 +53,7 @@ export default {
5353 if ( isFunction ( this . schema . set ) ) {
5454 this . schema . set ( this . model , newValue ) ;
5555 changed = true ;
56-
56+
5757 } else if ( this . schema . model ) {
5858 this . setModelValueByPath ( this . schema . model , newValue ) ;
5959 changed = true ;
@@ -68,7 +68,7 @@ export default {
6868
6969 if ( this . $parent . options && this . $parent . options . validateAfterChanged === true ) {
7070 this . validate ( ) ;
71- }
71+ }
7272 }
7373 }
7474 }
@@ -133,7 +133,7 @@ export default {
133133 setModelValueByPath ( path , value ) {
134134 // convert array indexes to properties
135135 let s = path . replace ( / \[ ( \w + ) \] / g, ".$1" ) ;
136-
136+
137137 // strip a leading dot
138138 s = s . replace ( / ^ \. / , "" ) ;
139139
@@ -157,9 +157,36 @@ export default {
157157 this . $root . $set ( o , k , value ) ;
158158 return ;
159159 }
160-
160+
161161 ++ i ;
162162 }
163+ } ,
164+
165+ getFieldID ( schema ) {
166+ // Try to get a reasonable default id from the schema,
167+ // then slugify it.
168+ if ( typeof schema . id !== "undefined" ) {
169+ // If an ID's been explicitly set, use it unchanged
170+ return schema . id ;
171+ } else {
172+ // Return the slugified version of either:
173+ return ( schema . inputName || schema . label || schema . model )
174+ // NB: This is a very simple, conservative, slugify function,
175+ // avoiding extra dependencies.
176+ . toString ( )
177+ . trim ( )
178+ . toLowerCase ( )
179+ // Spaces & underscores to dashes
180+ . replace ( / | _ / g, "-" )
181+ // Multiple dashes to one
182+ . replace ( / - { 2 , } / g, "-" )
183+ // Remove leading & trailing dashes
184+ . replace ( / ^ - + | - + $ / g, "" )
185+ // Remove anything that isn't a (English/ASCII) letter, number or dash.
186+ . replace ( / ( [ ^ a - z A - Z 0 - 9 - ] + ) / g, "" )
187+ ;
188+ }
163189 }
190+
164191 }
165192} ;
0 commit comments