feat(benchpress): add getStringParameter method to support text and radio inputs
This commit is contained in:
parent
39977bd3c2
commit
a2b58202a0
|
@ -2,11 +2,27 @@ import {DOM, document, location} from 'facade/dom';
|
|||
import {NumberWrapper, BaseException, isBlank} from 'facade/lang';
|
||||
|
||||
export function getIntParameter(name:string) {
|
||||
var el = DOM.querySelector(document, `input[name="${name}"]`);
|
||||
if (isBlank(el)) {
|
||||
return NumberWrapper.parseInt(getStringParameter(name), 10);
|
||||
}
|
||||
|
||||
export function getStringParameter(name:string) {
|
||||
var els = DOM.querySelectorAll(document, `input[name="${name}"]`)
|
||||
var value;
|
||||
var el;
|
||||
|
||||
for (var i=0; i<els.length; i++) {
|
||||
el = els[i];
|
||||
if ((el.type !== 'radio' && el.type !== 'checkbox') || el.checked) {
|
||||
value = el.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlank(value)) {
|
||||
throw new BaseException(`Could not find and input field with name ${name}`);
|
||||
}
|
||||
return NumberWrapper.parseInt(el.value, 10);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export function bindAction(selector:string, callback:Function) {
|
||||
|
|
|
@ -7,8 +7,14 @@
|
|||
var name = match[1];
|
||||
var value = match[2];
|
||||
var els = document.querySelectorAll('input[name="'+name+'"]');
|
||||
var el;
|
||||
for (var i=0; i<els.length; i++) {
|
||||
els[i].value = value;
|
||||
el = els[i];
|
||||
if (el.type === 'radio' || el.type === 'checkbox') {
|
||||
el.checked = el.value === value;
|
||||
} else {
|
||||
el.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
})();
|
Loading…
Reference in New Issue