jQWidgets Forums

This topic contains 4 replies, has 2 voices, and was last updated by  KBTibbs 11 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • ButtonGroup getSelection error #55095

    KBTibbs
    Blocked

    In it’s default state, the ButtonGroup has no buttons selected. In Radiobutton mode, this causes a javascript error when getting the selected value. This default case should be handled gracefully in the library by either catching the case and returning an appropriate value or by forcing a selection when entering RadioButton mode.

    Reproduction steps:
    1) Go to http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxbutton/buttongroup.htm
    2) Select “RadioButtons” mode
    3) Attempt to get the selection via javascript with the following command
    $("#jqxWidget").jqxButtonGroup("getSelection")

    Note the Javascript errors
    “TypeError: Cannot read property ‘num’ of null” – Chrome 35
    “Unable to get value of the property ‘num’: object is null or undefined” – Internet Explorer 9
    “TypeError: b._getSelectedButton(…) is null” – Firefox 25

    ButtonGroup getSelection error #55109

    Peter Stoev
    Keymaster

    Hi,

    Here’s a sample: http://jsfiddle.net/jqwidgets/dbkHp/ which illustrates how this should be used.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    ButtonGroup getSelection error #55134

    KBTibbs
    Blocked

    Are you telling me that an unhandled error is expected and desired behavior in your library?

    ButtonGroup getSelection error #55140

    Peter Stoev
    Keymaster

    Hi,

    No, as far as I know, I wrote you how to use the method.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    ButtonGroup getSelection error #55213

    KBTibbs
    Blocked

    And I wrote to you about the very real use case of checking the value outside of the element’s click event and how it can fail.

    Can you name another JQWidget that will catastrophically fail if JQX commands are run before user interaction? (Because that’s not the very *best* of paradigms.)

    Default mode handles this use case by returning undefined:

    RadioButton Mode handles this use case by returning an empty array:

    Checkbox Mode has a fatal error, which I (as a user of this library) cannot test or account for without modification of your library code.
    Leaving aside the completely inconsistent manner of return types (Sometimes it’s an int, sometimes an array, sometimes a string), calling a method on a variable that could be null without handling that case is just bad programming. Now, if you have a git repo I would gladly fork it, add the two lines of code to handle a null value, and send you a pull request.

    Otherwise:

    Which, I think, is a decent solution. Not only does it not error, it consolidates expected return types. This makes it easier for those of us using your library. Honestly, I would prefer that this control always return an array, but the posted solution above is literally the least amount of effort required to fix this error.

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

You must be logged in to reply to this topic.