Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #336 from ckeditor/t/335
Browse files Browse the repository at this point in the history
Fix: Improved binding of value attribute in InputTextView. Closes #335.
  • Loading branch information
Piotr Jasiun authored Nov 9, 2017
2 parents a3c4ae8 + 2c71df4 commit 823120b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/inputtext/inputtextview.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,12 @@ 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.
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/inputtext/inputtextview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 823120b

Please sign in to comment.