From 1582557bbb6d76ac7a3cecb1e45dad8ae786d23f 2014-04-17 14:56:30 From: Jessica B. Hamrick Date: 2014-04-17 14:56:30 Subject: [PATCH] Add placeholder attribute to text widgets --- diff --git a/IPython/html/static/widgets/js/widget_string.js b/IPython/html/static/widgets/js/widget_string.js index d5dd9eb..0298e2a 100644 --- a/IPython/html/static/widgets/js/widget_string.js +++ b/IPython/html/static/widgets/js/widget_string.js @@ -141,6 +141,16 @@ define(["widgets/js/widget"], function(WidgetManager){ .appendTo(this.$el); this.$el_to_style = this.$textbox; // Set default element to style this.update(); // Set defaults. + this.model.on('change:placeholder', function(model, value, options) { + this.update_placeholder(value); + }, this); + }, + + update_placeholder: function(value) { + if (!value) { + value = this.model.get('placeholder'); + } + this.$textbox.attr('placeholder', value); }, update: function(options){ diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index e3505c5..9f6aa30 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -23,6 +23,7 @@ class _StringWidget(DOMWidget): value = Unicode(help="String value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) + placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True) class HTMLWidget(_StringWidget):