Skip to content

Commit a2b5820

Browse files
committed
feat(benchpress): add getStringParameter method to support text and radio inputs
1 parent 39977bd commit a2b5820

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

modules/e2e_test_lib/src/benchmark_util.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@ import {DOM, document, location} from 'facade/dom';
22
import {NumberWrapper, BaseException, isBlank} from 'facade/lang';
33

44
export function getIntParameter(name:string) {
5-
var el = DOM.querySelector(document, `input[name="${name}"]`);
6-
if (isBlank(el)) {
5+
return NumberWrapper.parseInt(getStringParameter(name), 10);
6+
}
7+
8+
export function getStringParameter(name:string) {
9+
var els = DOM.querySelectorAll(document, `input[name="${name}"]`)
10+
var value;
11+
var el;
12+
13+
for (var i=0; i<els.length; i++) {
14+
el = els[i];
15+
if ((el.type !== 'radio' && el.type !== 'checkbox') || el.checked) {
16+
value = el.value;
17+
break;
18+
}
19+
}
20+
21+
if (isBlank(value)) {
722
throw new BaseException(`Could not find and input field with name ${name}`);
823
}
9-
return NumberWrapper.parseInt(el.value, 10);
24+
25+
return value;
1026
}
1127

1228
export function bindAction(selector:string, callback:Function) {

tools/build/snippets/url_params_to_form.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
var name = match[1];
88
var value = match[2];
99
var els = document.querySelectorAll('input[name="'+name+'"]');
10+
var el;
1011
for (var i=0; i<els.length; i++) {
11-
els[i].value = value;
12+
el = els[i];
13+
if (el.type === 'radio' || el.type === 'checkbox') {
14+
el.checked = el.value === value;
15+
} else {
16+
el.value = value;
17+
}
1218
}
1319
}
1420
})();

0 commit comments

Comments
 (0)