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

would be nice for <select> to support ng-size or size="{{expression}}" so we can set the size to the actual size for dynamic multiple selects #1619

Closed
jstrachan opened this issue Nov 28, 2012 · 21 comments

Comments

@jstrachan
Copy link

I've tried 1.0.2 and it seems any expression of the form <select size="{{something}}" which just gets set to size="0". I ended up having to hack around this with jquery which made me feel dirty ;) so wondered if there was a way of just allowing a size expression to be specified (or even defaulting it as the ng-options knows the size).

e.g. something like this...

      <select id="attributes" ng-size="whatnot.length" multiple ng-multiple="true" ng-model="selectedThings" ng-options="foo for foo in whatnot"></select>
@hotienvu
Copy link

hotienvu commented Mar 7, 2013

I'm having the same problem. My workaround is to write a custom ngSize directive that 2way-binds to something and update the select.size attribute.
https://gist.github.com/hotienvu/5105501

@mlegenhausen
Copy link

+1

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

@yorch
Copy link

yorch commented Aug 28, 2013

Same problem here using Angular 1.1.5

@btford btford reopened this Aug 28, 2013
@RavenHursT
Copy link

This bug is still present in 1.2

This is clearly a bug since whatever angular is doing, it's overriding DEFAULT HTML functionality. {{ someValue }} works in other attributes, why not here? Looks to me like there's a default of "0" hardcoded in AngularJs somewhere. Having to write custom directives for setting a size attribute on a native HTML element is pretty ridiculous. I can't believe this had to be "reopened"... I mean.. this is pretty basic..

http://www.w3schools.com/tags/att_select_size.asp

@btford
Copy link
Contributor

btford commented Nov 26, 2013

this is pretty basic..

@RavenHursT, would you like to submit a pull request for this feature then?

@joshkurz
Copy link
Contributor

so its strange that this works for input, but not select. The docs say that size can only be a non-negative integer http://www.w3.org/TR/html5/forms.html#attr-input-size. I know for a fact that when angular is parsing the attrs in collectDirectives the value of the select size attribute is already 0. This means that we cannot interpolate the value correctly, because we have lost the reference to the original string passed in from the view. Since the directives are collected before the compile functions are even ran, I would think the best solution is to create another directive that we know will not be defaulted by w3 standards.

@joshkurz
Copy link
Contributor

Here is a proposed directive ngSize. It only works on SELECT tags as that is all it is needed for. http://jsfiddle.net/joshkurz/DFyWX/2/

@RavenHursT
Copy link

"If you're not willing to fix it yourself, then you're not allowed to point out that closing an issue when it's a clear bug is not exactly the best way to support a community project" is a pretty lame cop-out.

If you're willing to take the time to go through and "clean out" old issues based solely on the frequency of their activity, then you'd think you may be willing to take the time to actually look into the problem when it's been a verifiable bug for over a year now...

@caitp
Copy link
Contributor

caitp commented Dec 6, 2013

Have y'all tried data-ng-attr-size="{{some interpolated expression}}" (since ~1.5, or cf17c6a at least) ? (edit I had previously written data-ng-size, which was a typo, oops!)

example: http://plnkr.co/edit/a1xLPGn2YeW0WavH2auD?p=preview

Considering you have this feature, can we close this as resolved by cf17c6a ?

@mlegenhausen
Copy link

I think there need be better documentation for ng-attr. It should be listed with the other directives and not only a little note in the Directives documentation.

@sidecut
Copy link

sidecut commented Feb 17, 2014

@caitp -- brilliant! Thanks!

However, @mlegenhausen is quite right. This is practically undocumented. One would expect it to be documented in the Directives section along with ngApp, ngBind, et al. (If it's not technically a directive, then by all means it should have its own section in the Developers Guide.)

@camden-kid
Copy link

@caitp Thanks. That worked like a dream.

@sidecut
Copy link

sidecut commented Feb 20, 2014

@caitp is right in that this issue should probably be closed, but with the proviso that a new issue about better documentation be created. Currently this is documented in one place only: the section entitled "Creating Custom Directives." This is misleading as it implies that ngAttr is available only when creating directives. On the contrary, it's available anywhere in Angular. Example here: http://plnkr.co/edit/ompMeVYn0jjPttTqIonP?p=preview

@caitp
Copy link
Contributor

caitp commented Feb 20, 2014

Where does it say/imply that it's only available when creating directives?

@sidecut
Copy link

sidecut commented Feb 20, 2014

It's implied because it only appears one section entitled "Creating Custom Directives." It's not using directives, but creating them, which is a natural dichotomy in software toolkits. Many users will skip that section, or will not think to look there when researching this topic. I used Angular quite productively for many months before I created a directive, so I would never think to read that section for a feature that is not limited to creating directives.

Plus, more importantly to me, it does not show up on the API page at all, which I would consider an omission. The API page is used as something of a menu of all the ng-* bits that a developer expects to find in Angular. (Whether that's the intention of that page is another matter.) Thus it functions as a reference guide, and as such, if something doesn't appear there, it's effectively undocumented.

@caitp
Copy link
Contributor

caitp commented Feb 20, 2014

It's true that it's not the best name for the section, because the section is really an overview of what directives are, including how they can be created. A more appropriate place for the ngAttr* stuff might be in the compiler docs, but people never seem to look there.

@sidecut
Copy link

sidecut commented Feb 20, 2014

I've dipped into the compiler docs, but I think most users would consider the compiler to be an advanced topic. Just the word "compiler" brings back memories of lexical analysis, parsers, and other topics from that one course you needed in order to complete the comp sci graduation requirements. ;-)

@ericsaupe
Copy link

I agree with @sidecut, I wouldn't spend time looking into compiler docs unless I was really desperate for something. The solution from @caitp is the way to go as it is using current Angular directives without doubling up code with a new directive.

@jibwa
Copy link

jibwa commented Jan 10, 2015

+1 @caitp data-ng-attr-size worked fine.

@JonahJ
Copy link

JonahJ commented Jun 17, 2016

+1

@Narretz Narretz self-assigned this Feb 15, 2017
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
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