diff options
| author | Misko Hevery | 2011-10-20 11:06:06 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-10-20 11:30:40 -0700 |
| commit | 7fc18b263dc74f52bb677e446f23e35d64948841 (patch) | |
| tree | 7e0bafb9966c17e5306387ca9fc1028cb7b1111b /src/widget | |
| parent | fabc9f77a3fae10c2b8d9a9ad1541e827cc0390d (diff) | |
| download | angular.js-7fc18b263dc74f52bb677e446f23e35d64948841.tar.bz2 | |
fix(radio): allows data-binding on value property. Closes#316
Diffstat (limited to 'src/widget')
| -rw-r--r-- | src/widget/input.js | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/widget/input.js b/src/widget/input.js index 0defd234..cf29d0f1 100644 --- a/src/widget/input.js +++ b/src/widget/input.js @@ -546,25 +546,24 @@ angularInputType('checkbox', function(inputElement) { </doc:example> */ angularInputType('radio', function(inputElement) { - var widget = this, - value = inputElement.attr('value'); + var widget = this; //correct the name inputElement.attr('name', widget.$id + '@' + inputElement.attr('name')); inputElement.bind('click', function() { widget.$apply(function() { if (inputElement[0].checked) { - widget.$emit('$viewChange', value); + widget.$emit('$viewChange', widget.$value); } }); }); widget.$render = function() { - inputElement[0].checked = value == widget.$viewValue; + inputElement[0].checked = isDefined(widget.$value) && (widget.$value == widget.$viewValue); }; if (inputElement[0].checked) { - widget.$viewValue = value; + widget.$viewValue = widget.$value; } }); @@ -735,7 +734,7 @@ angularWidget('input', function(inputElement){ pattern = new RegExp(pattern.substr(1, pattern.length - 2)); patternMatch = function(value) { return pattern.test(value); - } + }; } else { patternMatch = function(value) { var patternObj = modelScope.$eval(pattern); @@ -743,7 +742,7 @@ angularWidget('input', function(inputElement){ throw new Error('Expected ' + pattern + ' to be a RegExp but was ' + patternObj); } return patternObj.test(value); - } + }; } } @@ -771,6 +770,7 @@ angularWidget('input', function(inputElement){ controller: TypeController, controllerArgs: [inputElement]}); + watchElementProperty(this, widget, 'value', inputElement); watchElementProperty(this, widget, 'required', inputElement); watchElementProperty(this, widget, 'readonly', inputElement); watchElementProperty(this, widget, 'disabled', inputElement); @@ -864,15 +864,17 @@ angularWidget('textarea', angularWidget('input')); function watchElementProperty(modelScope, widget, name, element) { var bindAttr = fromJson(element.attr('ng:bind-attr') || '{}'), - match = /\s*{{(.*)}}\s*/.exec(bindAttr[name]); - widget['$' + name] = - // some browsers return true some '' when required is set without value. - isString(element.prop(name)) || !!element.prop(name) || - // this is needed for ie9, since it will treat boolean attributes as false - !!element[0].attributes[name]; + match = /\s*{{(.*)}}\s*/.exec(bindAttr[name]), + isBoolean = BOOLEAN_ATTR[name]; + widget['$' + name] = isBoolean + ? ( // some browsers return true some '' when required is set without value. + isString(element.prop(name)) || !!element.prop(name) || + // this is needed for ie9, since it will treat boolean attributes as false + !!element[0].attributes[name]) + : element.attr(name); if (bindAttr[name] && match) { modelScope.$watch(match[1], function(scope, value){ - widget['$' + name] = !!value; + widget['$' + name] = isBoolean ? !!value : value; widget.$emit('$validate'); }); } |
