Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

jqLite: .val() on <select multiple> with no options chosen should return an empty array instead of null #14370

Closed
mgol opened this issue Apr 4, 2016 · 1 comment · Fixed by #15104

Comments

@mgol
Copy link
Member

mgol commented Apr 4, 2016

Do you want to request a feature or report a bug?

A behavior change, though not a bug, strictly speaking.

What is the current behavior?

For the jqLite element representing a select element in the multiple variant with no options chosen the .val() getter returns null.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).

See http://plnkr.co/edit/QCWwa2AHNAhLKd2iyZPw

What is the expected behavior?

angular.element('<select multiple>').val() should return [].

What is the motivation / use case for changing the behavior?

The proposed change is in line with what jQuery 3 will be doing. Returning an empty array instead of null is more natural as the data type doesn't change.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.

All versions.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@mgol
Copy link
Member Author

mgol commented Jul 6, 2016

The jQuery issue about this change: jquery/jquery#2562.

mgol added a commit to mgol/angular.js that referenced this issue Sep 7, 2016
…tion

Fixes angular#14370

BREAKING CHANGE: For the jqLite element representing a select element in
the multiple variant with no options chosen the .val() getter used to return
null and now returns an empty array.

To migrate the code follow the example below:

Before:

HTML:

    <select multiple>
        <option>value 1</option>
        <option>value 2</option>
    </select>

JavaScript:

    var value = $element.val();
    if (value) {
        /* do something */
    }

After:

HTML:

    <select multiple>
        <option>value 1</option>
        <option>value 2</option>
    </select>

JavaScript:

    var value = $element.val();
    if (value.length > 0) {
        /* do something */
    }
mgol added a commit to mgol/angular.js that referenced this issue Sep 8, 2016
…tion

Fixes angular#14370

BREAKING CHANGE: For the jqLite element representing a select element in
the multiple variant with no options chosen the .val() getter used to return
null and now returns an empty array.

To migrate the code follow the example below:

Before:

HTML:

    <select multiple>
        <option>value 1</option>
        <option>value 2</option>
    </select>

JavaScript:

    var value = $element.val();
    if (value) {
        /* do something */
    }

After:

HTML:

    <select multiple>
        <option>value 1</option>
        <option>value 2</option>
    </select>

JavaScript:

    var value = $element.val();
    if (value.length > 0) {
        /* do something */
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant