Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
48d71d0c
Commit
48d71d0c
authored
Mar 03, 2013
by
ruado1987
Committed by
Richard Gibson
Mar 22, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13514: Set selectedIndex to -1 when non-matching value is set on a select. Close gh-1191.
parent
ab5b0ff3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
attributes.js
src/attributes.js
+14
-7
attributes.js
test/unit/attributes.js
+16
-0
No files found.
src/attributes.js
View file @
48d71d0c
...
@@ -275,13 +275,20 @@ jQuery.extend({
...
@@ -275,13 +275,20 @@ jQuery.extend({
},
},
set
:
function
(
elem
,
value
)
{
set
:
function
(
elem
,
value
)
{
var
values
=
jQuery
.
makeArray
(
value
);
var
optionSet
,
option
,
options
=
elem
.
options
,
jQuery
(
elem
).
find
(
"option"
).
each
(
function
()
{
values
=
jQuery
.
makeArray
(
value
),
this
.
selected
=
jQuery
.
inArray
(
jQuery
(
this
).
val
(),
values
)
>=
0
;
i
=
options
.
length
;
});
while
(
i
--
)
{
if
(
!
values
.
length
)
{
option
=
options
[
i
];
if
(
(
option
.
selected
=
jQuery
.
inArray
(
jQuery
(
option
).
val
(),
values
)
>=
0
)
)
{
optionSet
=
true
;
}
}
// force browsers to behave consistently when non-matching value is set
if
(
!
optionSet
)
{
elem
.
selectedIndex
=
-
1
;
elem
.
selectedIndex
=
-
1
;
}
}
return
values
;
return
values
;
...
...
test/unit/attributes.js
View file @
48d71d0c
...
@@ -850,6 +850,22 @@ test( "val()", function() {
...
@@ -850,6 +850,22 @@ test( "val()", function() {
equal
(
jQuery
(
"<option/>"
).
val
(
"test"
).
attr
(
"value"
),
"test"
,
"Setting value sets the value attribute"
);
equal
(
jQuery
(
"<option/>"
).
val
(
"test"
).
attr
(
"value"
),
"test"
,
"Setting value sets the value attribute"
);
});
});
test
(
"val() with non-matching values on dropdown list"
,
function
()
{
expect
(
3
);
jQuery
(
"#select5"
).
val
(
""
);
equal
(
jQuery
(
"#select5"
).
val
(),
null
,
"Non-matching set on select-one"
);
var
select6
=
jQuery
(
"<select multiple id=
\"
select6
\"
><option value=
\"
1
\"
>A</option><option value=
\"
2
\"
>B</option></select>"
).
appendTo
(
"#form"
);
jQuery
(
select6
).
val
(
"nothing"
);
equal
(
jQuery
(
select6
).
val
(),
null
,
"Non-matching set (single value) on select-multiple"
);
jQuery
(
select6
).
val
(
[
"nothing1"
,
"nothing2"
]
);
equal
(
jQuery
(
select6
).
val
(),
null
,
"Non-matching set (array of values) on select-multiple"
);
select6
.
remove
();
});
if
(
"value"
in
document
.
createElement
(
"meter"
)
&&
if
(
"value"
in
document
.
createElement
(
"meter"
)
&&
"value"
in
document
.
createElement
(
"progress"
)
)
{
"value"
in
document
.
createElement
(
"progress"
)
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment