Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Allow ng-trim to work on radio buttons #11859

Closed
Drarok opened this issue May 12, 2015 · 7 comments
Closed

Allow ng-trim to work on radio buttons #11859

Drarok opened this issue May 12, 2015 · 7 comments

Comments

@Drarok
Copy link

Drarok commented May 12, 2015

I'd like to have the option to use ng-trim on radio inputs, not just text inputs. I'm using Angular 1.2.x, but have confirmed the feature is not available in 1.3.x or 1.4.x.

JSFiddle example against 1.4.x: http://jsfiddle.net/rgewfgbL/5/

@Narretz
Copy link
Contributor

Narretz commented May 13, 2015

ngTrim is used to trim user input, i.e. trailing / leading whitespace in text inputs. If the value for radio buttons contains white space is in 90% of all cases at the discretion of the developer. If you use user defined values for your radio, I can see whitespace being an annoyance, but this is simply not what ngTrim is about. It's about trimming user input text. So I don't think ngTrim for radios is something we want.

@pkozlowski-opensource
Copy link
Member

@Narretz while I agree with your analysis, it looks odd that this radio button is not selected, no?

@Narretz
Copy link
Contributor

Narretz commented May 13, 2015

Yeah, that's odd ...

@Narretz
Copy link
Contributor

Narretz commented May 13, 2015

When the value is retrieved from the element, whitespace is automatically trimmed by the browser (Firefox at least). radio buttons compares attr.value == $viewValie. We could trim the $viewValue in this case, too to match this behavior. However, I don't know what the spec says about this.

@Narretz
Copy link
Contributor

Narretz commented May 13, 2015

It's also possible that the trimming happens when angular creates the attrs for the directive.

@Drarok
Copy link
Author

Drarok commented May 13, 2015

I've created an updated fiddle that shows the value as seen by the browser, and proves this to be an Angular problem, not a browser one: http://jsfiddle.net/rgewfgbL/6/

@Narretz Narretz self-assigned this May 26, 2015
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Jun 11, 2015
Allow elements of type input[type=radio] to specify ng-trim.
Do not trim attributes values by default.

BREAKING CHANGE:
Attribute values are not trimmed by default

Migration: when depending on attribute values to be trimmed, then manually trim them.

Close: angular#11859
@lgalfaso lgalfaso assigned lgalfaso and unassigned Narretz Jun 11, 2015
@snshn
Copy link

snshn commented Aug 19, 2015

Please fix this one.

<input type="radio" ng-model="format" ng-trim="false" value=" " /> sets $scope.format to an empty string (""), not to a " ". Using the &nbsp; and similar tricks does not work.

Narretz pushed a commit to Narretz/angular.js that referenced this issue Jun 8, 2016
Allow input[type=radio] elements to specify ng-trim.

Closes: angular#12091
Fixes: angular#11859
Narretz pushed a commit to Narretz/angular.js that referenced this issue Jun 8, 2016
Allow input[type=radio] elements to specify ng-trim.

Closes: angular#12091
Fixes: angular#11859
@gkalpak gkalpak modified the milestones: Backlog, Purgatory Jun 8, 2016
Narretz pushed a commit to Narretz/angular.js that referenced this issue Jun 9, 2016
Allow input[type=radio] elements to specify ng-trim.

Closes: angular#12091
Fixes: angular#11859
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants