##// END OF EJS Templates
handle empty string in ToggleButtonsWidget
MinRK -
Show More
@@ -58,7 +58,7 define(["notebook/js/widgets/widget"], function(WidgetManager){
58
58
59 if (options === undefined || options.updated_view != this) {
59 if (options === undefined || options.updated_view != this) {
60 var selected_item_text = this.model.get('value_name');
60 var selected_item_text = this.model.get('value_name');
61 if (selected_item_text.length === 0) {
61 if (selected_item_text.trim().length === 0) {
62 this.$droplabel.html(" ");
62 this.$droplabel.html(" ");
63 } else {
63 } else {
64 this.$droplabel.text(selected_item_text);
64 this.$droplabel.text(selected_item_text);
@@ -233,18 +233,24 define(["notebook/js/widgets/widget"], function(WidgetManager){
233 var items = this.model.get('value_names');
233 var items = this.model.get('value_names');
234 var disabled = this.model.get('disabled');
234 var disabled = this.model.get('disabled');
235 var that = this;
235 var that = this;
236 var item_html;
236 _.each(items, function(item, index) {
237 _.each(items, function(item, index) {
237 var item_query = ' :contains("' + item + '")';
238 if (item.trim().length == 0) {
238 if (that.$buttongroup.find(item_query).length === 0) {
239 item_html = " ";
239 $('<button />')
240 } else {
241 item_html = IPython.utils.escape_html(item);
242 }
243 var item_query = '[data-value="' + item + '"]';
244 var $item_element = that.$buttongroup.find(item_query);
245 if (!$item_element.length) {
246 $item_element = $('<button/>')
240 .attr('type', 'button')
247 .attr('type', 'button')
241 .addClass('btn')
248 .addClass('btn')
242 .text(item)
249 .html(item_html)
243 .appendTo(that.$buttongroup)
250 .appendTo(that.$buttongroup)
251 .attr('data-value', item)
244 .on('click', $.proxy(that.handle_click, that));
252 .on('click', $.proxy(that.handle_click, that));
245 }
253 }
246
247 var $item_element = that.$buttongroup.find(item_query);
248 if (that.model.get('value_name') == item) {
254 if (that.model.get('value_name') == item) {
249 $item_element.addClass('active');
255 $item_element.addClass('active');
250 } else {
256 } else {
@@ -255,7 +261,7 define(["notebook/js/widgets/widget"], function(WidgetManager){
255
261
256 // Remove items that no longer exist.
262 // Remove items that no longer exist.
257 this.$buttongroup.find('button').each(function(i, obj) {
263 this.$buttongroup.find('button').each(function(i, obj) {
258 var value = $(obj).text();
264 var value = $(obj).data('value');
259 var found = false;
265 var found = false;
260 _.each(items, function(item, index) {
266 _.each(items, function(item, index) {
261 if (item == value) {
267 if (item == value) {
@@ -285,7 +291,7 define(["notebook/js/widgets/widget"], function(WidgetManager){
285
291
286 // Calling model.set will trigger all of the other views of the
292 // Calling model.set will trigger all of the other views of the
287 // model to update.
293 // model to update.
288 this.model.set('value_name', $(e.target).text(), {updated_view: this});
294 this.model.set('value_name', $(e.target).data('value'), {updated_view: this});
289 this.touch();
295 this.touch();
290 },
296 },
291 });
297 });
General Comments 0
You need to be logged in to leave comments. Login now