##// END OF EJS Templates
listening for change on SelectView and SelectMultipleView
Nicholas Bollweg -
Show More
@@ -431,7 +431,8 b' define(['
431 this.$listbox = $('<select />')
431 this.$listbox = $('<select />')
432 .addClass('widget-listbox form-control')
432 .addClass('widget-listbox form-control')
433 .attr('size', 6)
433 .attr('size', 6)
434 .appendTo(this.$el);
434 .appendTo(this.$el)
435 .on('change', $.proxy(this.handle_change, this));
435 this.update();
436 this.update();
436 },
437 },
437
438
@@ -453,8 +454,7 b' define(['
453 .text(item)
454 .text(item)
454 .attr('data-value', encodeURIComponent(item))
455 .attr('data-value', encodeURIComponent(item))
455 .attr('selected_label', item)
456 .attr('selected_label', item)
456 .appendTo(that.$listbox)
457 .appendTo(that.$listbox);
457 .on('click', $.proxy(that.handle_click, that));
458 }
458 }
459 });
459 });
460
460
@@ -503,37 +503,50 b' define(['
503 }
503 }
504 },
504 },
505
505
506 handle_click: function (e) {
506 handle_change: function (e) {
507 /**
507 /**
508 * Handle when a value is clicked.
508 * Handle when a new value is selected.
509 *
509 *
510 * Calling model.set will trigger all of the other views of the
510 * Calling model.set will trigger all of the other views of the
511 * model to update.
511 * model to update.
512 */
512 */
513 this.model.set('selected_label', $(e.target).text(), {updated_view: this});
513 this.model.set('selected_label', this.$listbox.val(), {updated_view: this});
514 this.touch();
514 this.touch();
515 },
515 },
516 });
516 });
517
518
517 var SelectMultipleView = SelectView.extend({
519 var SelectMultipleView = SelectView.extend({
518 render: function(){
520 render: function(){
521 /**
522 * Called when view is rendered.
523 */
519 SelectMultipleView.__super__.render.apply(this);
524 SelectMultipleView.__super__.render.apply(this);
520 this.$el.removeClass('widget-select')
525 this.$el.removeClass('widget-select')
521 .addClass('widget-select-multiple');
526 .addClass('widget-select-multiple');
522 this.$listbox.attr('multiple', true)
527 this.$listbox.attr('multiple', true)
523 .on('input', $.proxy(this.handle_click, this));
528 .on('change', $.proxy(this.handle_change, this));
524 return this;
529 return this;
525 },
530 },
526
531
527 update: function(){
532 update: function(){
533 /**
534 * Update the contents of this view
535 *
536 * Called when the model is changed. The model may have been
537 * changed by another view or by a state update from the back-end.
538 */
528 SelectMultipleView.__super__.update.apply(this, arguments);
539 SelectMultipleView.__super__.update.apply(this, arguments);
529 this.$listbox.val(this.model.get('selected_labels'));
540 this.$listbox.val(this.model.get('selected_labels'));
530 },
541 },
531
542
532 handle_click: function (e) {
543 handle_change: function (e) {
533 // Handle when a value is clicked.
544 /**
534
545 * Handle when a new value is selected.
535 // Calling model.set will trigger all of the other views of the
546 *
536 // model to update.
547 * Calling model.set will trigger all of the other views of the
548 * model to update.
549 */
537 this.model.set('selected_labels',
550 this.model.set('selected_labels',
538 (this.$listbox.val() || []).slice(),
551 (this.$listbox.val() || []).slice(),
539 {updated_view: this});
552 {updated_view: this});
@@ -541,6 +554,7 b' define(['
541 },
554 },
542 });
555 });
543
556
557
544 return {
558 return {
545 'DropdownView': DropdownView,
559 'DropdownView': DropdownView,
546 'RadioButtonsView': RadioButtonsView,
560 'RadioButtonsView': RadioButtonsView,
General Comments 0
You need to be logged in to leave comments. Login now