From de2b210e99225c4d58b40675ae42f2fba0971d8b Mon Sep 17 00:00:00 2001 From: Thomas Pronk Date: Mon, 17 May 2021 23:10:47 +0100 Subject: [PATCH] Retain entered text (and placeholder) upon resize --- src/visual/TextBox.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/visual/TextBox.js b/src/visual/TextBox.js index 0795ea0..cced804 100644 --- a/src/visual/TextBox.js +++ b/src/visual/TextBox.js @@ -59,6 +59,12 @@ export class TextBox extends util.mix(VisualStim).with(ColorMixin) '', this._onChange(true, true) ); + this._addAttribute( + 'placeholder', + text, + '', + this._onChange(true, true) + ); this._addAttribute( 'anchor', anchor, @@ -404,6 +410,9 @@ export class TextBox extends util.mix(VisualStim).with(ColorMixin) { this._pixi.destroy(true); } + // Get the currently entered text + let enteredText = this._pixi !== undefined? this._pixi.text: ''; + // Create new TextInput this._pixi = new TextInput(this._getTextInputOptions()); // listeners required for regular textboxes, but may cause problems with button stimuli @@ -425,7 +434,8 @@ export class TextBox extends util.mix(VisualStim).with(ColorMixin) } if (this._editable) { - this._pixi.placeholder = this._text; + this.text = enteredText; + this._pixi.placeholder = this._placeholder; } else {