Show More
@@ -0,0 +1,3 b'' | |||
|
1 | * `TextWidget` and `TextareaWidget` objects now include a | |
|
2 | `placeholder` attribute, for displaying placeholder text before the | |
|
3 | user has typed anything. |
@@ -71,6 +71,11 b' define(["widgets/js/widget"], function(WidgetManager){' | |||
|
71 | 71 | this.update(); // Set defaults. |
|
72 | 72 | |
|
73 | 73 | this.model.on('msg:custom', $.proxy(this._handle_textarea_msg, this)); |
|
74 | this.model.on('change:placeholder', function(model, value, options) { | |
|
75 | this.update_placeholder(value); | |
|
76 | }, this); | |
|
77 | ||
|
78 | this.update_placeholder(); | |
|
74 | 79 | }, |
|
75 | 80 | |
|
76 | 81 | _handle_textarea_msg: function (content){ |
@@ -80,6 +85,13 b' define(["widgets/js/widget"], function(WidgetManager){' | |||
|
80 | 85 | } |
|
81 | 86 | }, |
|
82 | 87 | |
|
88 | update_placeholder: function(value) { | |
|
89 | if (!value) { | |
|
90 | value = this.model.get('placeholder'); | |
|
91 | } | |
|
92 | this.$textbox.attr('placeholder', value); | |
|
93 | }, | |
|
94 | ||
|
83 | 95 | scroll_to_bottom: function (){ |
|
84 | 96 | // Scroll the text-area view to the bottom. |
|
85 | 97 | this.$textbox.scrollTop(this.$textbox[0].scrollHeight); |
@@ -141,6 +153,18 b' define(["widgets/js/widget"], function(WidgetManager){' | |||
|
141 | 153 | .appendTo(this.$el); |
|
142 | 154 | this.$el_to_style = this.$textbox; // Set default element to style |
|
143 | 155 | this.update(); // Set defaults. |
|
156 | this.model.on('change:placeholder', function(model, value, options) { | |
|
157 | this.update_placeholder(value); | |
|
158 | }, this); | |
|
159 | ||
|
160 | this.update_placeholder(); | |
|
161 | }, | |
|
162 | ||
|
163 | update_placeholder: function(value) { | |
|
164 | if (!value) { | |
|
165 | value = this.model.get('placeholder'); | |
|
166 | } | |
|
167 | this.$textbox.attr('placeholder', value); | |
|
144 | 168 | }, |
|
145 | 169 | |
|
146 | 170 | update: function(options){ |
@@ -7,8 +7,8 b' casper.notebook_test(function () {' | |||
|
7 | 7 | this.execute_cell_then(index); |
|
8 | 8 | |
|
9 | 9 | var string_index = this.append_cell( |
|
10 | 'string_widget = [widgets.TextWidget(value = "xyz"),\n' + | |
|
11 | ' widgets.TextareaWidget(value = "xyz"),\n' + | |
|
10 | 'string_widget = [widgets.TextWidget(value = "xyz", placeholder = "abc"),\n' + | |
|
11 | ' widgets.TextareaWidget(value = "xyz", placeholder = "def"),\n' + | |
|
12 | 12 | ' widgets.HTMLWidget(value = "xyz"),\n' + |
|
13 | 13 | ' widgets.LatexWidget(value = "$\\\\LaTeX{}$")]\n' + |
|
14 | 14 | '[display(widget) for widget in string_widget]\n'+ |
@@ -41,5 +41,13 b' casper.notebook_test(function () {' | |||
|
41 | 41 | this.test.assert(this.cell_element_exists(string_index, |
|
42 | 42 | '.widget-area .widget-subarea div span.MathJax_Preview'), |
|
43 | 43 | 'MathJax parsed the LaTeX successfully.'); |
|
44 | ||
|
45 | this.test.assert(this.cell_element_function(index, | |
|
46 | '.widget-area .widget-subarea .widget-hbox textarea', 'attr', ['placeholder'])=='def', | |
|
47 | 'Python set textarea placeholder.'); | |
|
48 | ||
|
49 | this.test.assert(this.cell_element_function(index, | |
|
50 | '.widget-area .widget-subarea .widget-hbox-single input[type=text]', 'attr', ['placeholder'])=='abc', | |
|
51 | 'Python set textbox placehoder.'); | |
|
44 | 52 | }); |
|
45 | }); No newline at end of file | |
|
53 | }); |
@@ -23,6 +23,7 b' class _StringWidget(DOMWidget):' | |||
|
23 | 23 | value = Unicode(help="String value", sync=True) |
|
24 | 24 | disabled = Bool(False, help="Enable or disable user changes", sync=True) |
|
25 | 25 | description = Unicode(help="Description of the value this widget represents", sync=True) |
|
26 | placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True) | |
|
26 | 27 | |
|
27 | 28 | |
|
28 | 29 | class HTMLWidget(_StringWidget): |
@@ -7,7 +7,7 b'' | |||
|
7 | 7 | ] |
|
8 | 8 | ], |
|
9 | 9 | "name": "", |
|
10 | "signature": "sha256:9a70b52f0b16861d1cd6a8342b233247958977a52bde8d3efd69d21131ce1926" | |
|
10 | "signature": "sha256:5ac3a85c8bb2f9bb3cd63b524bbb626ab1531176b43a109d13f5d7794f805eee" | |
|
11 | 11 | }, |
|
12 | 12 | "nbformat": 3, |
|
13 | 13 | "nbformat_minor": 0, |
@@ -31,7 +31,7 b'' | |||
|
31 | 31 | "language": "python", |
|
32 | 32 | "metadata": {}, |
|
33 | 33 | "outputs": [], |
|
34 |
"prompt_number": |
|
|
34 | "prompt_number": 2 | |
|
35 | 35 | }, |
|
36 | 36 | { |
|
37 | 37 | "cell_type": "heading", |
@@ -298,6 +298,39 b'' | |||
|
298 | 298 | } |
|
299 | 299 | ], |
|
300 | 300 | "prompt_number": 10 |
|
301 | }, | |
|
302 | { | |
|
303 | "cell_type": "markdown", | |
|
304 | "metadata": {}, | |
|
305 | "source": [ | |
|
306 | "Some widgets have special attributes. For example, text boxes and text areas can specify the `placeholder` attribute, which will set \"placeholder\" text to be displayed before the user has typed anything:" | |
|
307 | ] | |
|
308 | }, | |
|
309 | { | |
|
310 | "cell_type": "code", | |
|
311 | "collapsed": false, | |
|
312 | "input": [ | |
|
313 | "mytextwidget = widgets.TextWidget()\n", | |
|
314 | "mytextwidget.placeholder = \"type something here\"\n", | |
|
315 | "display(mytextwidget)" | |
|
316 | ], | |
|
317 | "language": "python", | |
|
318 | "metadata": {}, | |
|
319 | "outputs": [], | |
|
320 | "prompt_number": 4 | |
|
321 | }, | |
|
322 | { | |
|
323 | "cell_type": "code", | |
|
324 | "collapsed": false, | |
|
325 | "input": [ | |
|
326 | "mytextareawidget = widgets.TextareaWidget()\n", | |
|
327 | "mytextareawidget.placeholder = \"your text here\"\n", | |
|
328 | "display(mytextareawidget)" | |
|
329 | ], | |
|
330 | "language": "python", | |
|
331 | "metadata": {}, | |
|
332 | "outputs": [], | |
|
333 | "prompt_number": 5 | |
|
301 | 334 | } |
|
302 | 335 | ], |
|
303 | 336 | "metadata": {} |
General Comments 0
You need to be logged in to leave comments.
Login now