@@ -243,7 +243,7 @@ wp.widgets.Form = (function( api, $, _ ) {
243243 } ,
244244
245245 /**
246- * Create elements to link setting value properties with corresponding inputs in the form.
246+ * Link setting value properties with corresponding inputs in the form.
247247 *
248248 * @returns {void }
249249 */
@@ -252,17 +252,19 @@ wp.widgets.Form = (function( api, $, _ ) {
252252 initialInstanceData = form . getValue ( ) ;
253253 form . syncedProperties = { } ;
254254 form . container . find ( ':input[data-field]' ) . each ( function ( ) {
255- var input = $ ( this ) , field = input . data ( 'field' ) , syncedProperty ;
255+ var input = $ ( this ) , field = input . data ( 'field' ) ;
256256 if ( _ . isUndefined ( initialInstanceData [ field ] ) ) {
257257 return ;
258258 }
259-
260- // @todo : use setState instead of updating the model directly
261- syncedProperty = form . createSyncedPropertyValue ( form . model , field ) ;
262- syncedProperty . element = new api . Element ( input ) ;
263- syncedProperty . element . set ( initialInstanceData [ field ] ) ;
264- syncedProperty . element . sync ( syncedProperty . value ) ;
265- form . syncedProperties [ field ] = syncedProperty ;
259+ input . on ( 'change' , function ( event ) {
260+ var newValue = { } ;
261+ newValue [ field ] = event . target . value ;
262+ form . setState ( newValue ) ;
263+ } ) ;
264+ form . model . bind ( function ( newData ) {
265+ var newValue = newData [ field ] ;
266+ input . val ( newValue ) ;
267+ } ) ;
266268 } ) ;
267269 } ,
268270
0 commit comments