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