Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
3ddea2a4
...
3ddea2a4b948a134020315bbcb130083ad9f7b71
authored
2012-10-24 13:39:17 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refs #259 - refactored
7c2137eb
1 parent
7c2137eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
38 deletions
modules/clientutils.js
modules/clientutils.js
View file @
3ddea2a
...
...
@@ -415,46 +415,44 @@
* @return Mixed
*/
this
.
getFieldValue
=
function
getFieldValue
(
inputName
)
{
function
getSingleValue
(
input
)
{
try
{
type
=
input
.
getAttribute
(
'type'
).
toLowerCase
();
}
catch
(
e
)
{
type
=
'other'
;
}
if
([
'checkbox'
,
'radio'
].
indexOf
(
type
)
===
-
1
)
{
return
input
.
value
;
}
// single checkbox or… radio button (weird, I know)
if
(
input
.
hasAttribute
(
'value'
))
{
return
input
.
checked
?
input
.
getAttribute
(
'value'
)
:
undefined
;
}
return
input
.
checked
;
}
function
getMultipleValues
(
inputs
)
{
type
=
inputs
[
0
].
getAttribute
(
'type'
).
toLowerCase
();
if
(
type
===
'radio'
)
{
var
value
;
[].
forEach
.
call
(
inputs
,
function
(
radio
)
{
value
=
radio
.
checked
?
radio
.
value
:
undefined
;
});
return
value
;
}
else
if
(
type
===
'checkbox'
)
{
var
values
=
[];
[].
forEach
.
call
(
inputs
,
function
(
checkbox
)
{
if
(
checkbox
.
checked
)
{
values
.
push
(
checkbox
.
value
);
}
});
return
values
;
}
}
var
inputs
=
this
.
findAll
(
'[name="'
+
inputName
+
'"]'
),
type
;
switch
(
inputs
.
length
)
{
case
0
:
return
null
;
case
1
:
//this.log(inputs[0].nodeName.toLowerCase(), "error");
var
input
=
inputs
[
0
];
try
{
type
=
input
.
getAttribute
(
'type'
).
toLowerCase
();
}
catch
(
e
)
{
type
=
'other'
;
}
if
([
'checkbox'
,
'radio'
].
indexOf
(
type
)
===
-
1
)
{
return
input
.
value
;
}
// single checkbox or… radio button (weird, I know)
if
(
input
.
hasAttribute
(
'value'
))
{
return
input
.
checked
?
input
.
getAttribute
(
'value'
)
:
undefined
;
}
else
{
return
input
.
checked
;
}
break
;
default
:
type
=
inputs
[
0
].
getAttribute
(
'type'
).
toLowerCase
();
if
(
type
===
'radio'
)
{
var
value
;
[].
forEach
.
call
(
inputs
,
function
(
radio
)
{
value
=
radio
.
checked
?
radio
.
value
:
undefined
;
});
return
value
;
}
else
if
(
type
===
'checkbox'
)
{
var
values
=
[];
[].
forEach
.
call
(
inputs
,
function
(
checkbox
)
{
if
(
checkbox
.
checked
)
{
values
.
push
(
checkbox
.
value
);
}
});
return
values
;
}
break
;
case
0
:
return
null
;
case
1
:
return
getSingleValue
(
inputs
[
0
]);
default
:
return
getMultipleValues
(
inputs
);
}
};
...
...
Please
register
or
sign in
to post a comment