jQWidgets Forums

jQuery UI Widgets Forums Lists ListBox IE8 returns wrong number of selected items

This topic contains 3 replies, has 2 voices, and was last updated by  Peter Stoev 12 years, 8 months ago.

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

  • carlo
    Participant

    Hello,

    we found a strange bug with IE8. The following page contain a listbox with 9 items. The listbox is multi selectable and all items are selected. If you click on ‘Get selected items’ then the number of selected items is displayed.

    If you use IE8, then 10 selected items are reported instead of 9. If you remove the line with ‘jqxDateTimeInput’, IE8 reports correct 9 selected elements.

    Here the link to the page: http://85.214.211.237/webtest/jqx/jqxlistbox.html

    Best Regards,
    Karlheinz


    Peter Stoev
    Keymaster

    Hi Karlheinz,

    The ‘getSelectedItems’ method returns an array of selected listbox items. It does not return the count of the selected items. You shouldn’t count on the Array’s length property because in browsers like IE8 where indexOf and lastIndexOf are not defined, the last item in an array will be always a function and the minimum length will be at least 1. You may also ask why the count is correct without a jqxDateTimeInput and the answer is that the jqxDateTimeInput uses the Array’s indexOf method and if it is not defined, the widget defines it. To count the number of selected items, use a ‘for loop’ and check for defined label property and increase the counter by one.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    carlo
    Participant

    Hi Peter,

    thank you for the explanation. Thats a programmers nightmare: adding a datetime widget crashes the listbox code ! Jscript in combination with each browsers idiosyncrasy is an untestable team. Hopefully jscript is never ever used for serious programming.

    We do now:

    function GetSelectedItemsCount(id)
    {
    var items = $(id).jqxListBox('getSelectedItems');
    var n = 0;
    for(var i=0; i < items.length; i++)
    {
    var item = items[i];
    if (typeof item.label == "string") // === checks also for type
    n++;
    //if (typeof item.label === "undefined") // === checks also for type
    }
    return n;
    }

    Best Regards,
    Karlheinz


    Peter Stoev
    Keymaster

    Hi Karlheinz,

    As I already written in the previous post, the problem is not adding a jqxDateTimeInput or any other widget or script. The problem is the assumption that ‘length’ should return the number of selected items. The ‘getSelectedItems’ method returns an Array object that contains the selected Items. However, the Array object may have additional enumerable properties and functions defined by any script or code on your web page and ‘length’ returns the number of enumerable properties/functions in the Array object.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

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

You must be logged in to reply to this topic.