Browse Source

Fix: Improved binding of value attribute in InputTextView.

Oskar Wróbel 8 years ago
parent
commit
f2abc9de15

+ 2 - 13
packages/ckeditor5-ui/src/inputtext/inputtextview.js

@@ -65,24 +65,13 @@ export default class InputTextView extends View {
 				],
 				id: bind.to( 'id' ),
 				placeholder: bind.to( 'placeholder' ),
-				readonly: bind.to( 'isReadOnly' )
+				readonly: bind.to( 'isReadOnly' ),
+				value: bind.to( 'value' )
 			}
 		} );
 	}
 
 	/**
-	 * @inheritDoc
-	 */
-	render() {
-		super.render();
-
-		// Note: `value` cannot be an HTML attribute, because it doesn't change HTMLInputElement value once changed.
-		this.on( 'change:value', ( evt, propertyName, value ) => {
-			this.element.value = value || '';
-		} );
-	}
-
-	/**
 	 * Moves the focus to the input and selects the value.
 	 */
 	select() {

+ 17 - 0
packages/ckeditor5-ui/tests/inputtext/inputtextview.js

@@ -36,6 +36,12 @@ describe( 'InputTextView', () => {
 				view.value = 'baz';
 
 				expect( view.element.value ).to.equal( 'baz' );
+
+				// To be sure that value can be changed multiple times using inline value attribute.
+				// There was a related bug in Chrome.
+				view.value = 'biz';
+
+				expect( view.element.value ).to.equal( 'biz' );
 			} );
 
 			it( 'should set to empty string when using `falsy` values', () => {
@@ -45,6 +51,17 @@ describe( 'InputTextView', () => {
 					expect( view.element.value ).to.equal( '' );
 				} );
 			} );
+
+			// See ckeditor5-ui/issues/335.
+			it( 'should set element value when value was defined before view#render', () => {
+				view = new InputTextView();
+
+				view.value = 'baz';
+
+				view.render();
+
+				expect( view.element.value ).to.equal( 'baz' );
+			} );
 		} );
 
 		describe( 'id', () => {