jQWidgets Forums

jQuery UI Widgets Forums Lists ComboBox Setting selectedIndex(-1) with Knockout does not deselect item

This topic contains 2 replies, has 2 voices, and was last updated by  Makla 12 years, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author

  • Makla
    Participant

    Setting selectedIndex(-1) doesn’t update input field. I think that it should automatically clear input when setting selectedIndex to -1.

    $(document).ready(function () {
    // View Model
    var listModel = function (items) {
    this.items = ko.observableArray(items);
    this.itemToAdd = ko.observable("");
    this.disabled = ko.observable(false);
    this.selectedIndex = ko.observable(1);
    // adds new item.
    this.addItem = function () {
    if (this.itemToAdd() != "") {
    this.items.push(this.itemToAdd()); // Adds the item. Writing to the "items" observableArray causes any associated UI to update.
    this.itemToAdd(""); // Clears the text box, because it's bound to the "itemToAdd" observable
    }
    } .bind(this); // Ensure that "this" is always this view model
    // removes item.
    this.removeItem = function () {
    this.items.pop();
    }
    // gets the selected index.
    this.getIndex = function () {
    alert("Selected Index: " + this.selectedIndex());
    }
    // sets the selected index.
    this.setIndex = function () {
    this.selectedIndex(-1);
    }
    };
    $("#list").on('bindingComplete', function (event) {
    });
    ko.applyBindings(new listModel(["Caffé Latte", "Cortado", "Espresso"]));
    });

    Peter Stoev
    Keymaster

    Hi Makla,

    The Input field may contain data typed by the user, not the selected item so the field should not be cleared. Only the selection in the popup should be cleared.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.