mdSelect clear selection (unselect)
mdAutocomplete has a cross you can click to clear the value. Something like this would be awesome for mdSelect. Currently it looks like the only way is to add a blank mdOption. If possible, would it make sense to only show this if the mdSelect is not required?
@ThomasBurleson could we coordinate with the UX team on this and get their thoughts?
This seems like a good suggestion but I don't think we can get to it before our 1.0 release.
or, selecting the same option again will clear the value and display the placeholder/label
That seems like poor UX
On Tue, 4 Aug 2015 3:35 pm Charlie-Ng [email protected] wrote:
or, selecting the same option again will clear the value and display the placeholder/label
— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/1901#issuecomment-127780777.
I just feel like this is another way to cancel selection, isn't it?
The standard way to clear a HTML Select field is to add a blank option.
I am facing the same kind of issue with floating label, so I think it might be reopened. My use case :
<md-input-container>
<label>My Label</label>
<md-select ng-model="myModel">
<md-option value=""></md-option>
<md-option ng-repeat="value in [...]" ng-value="value">{{value}}</md-option>
</md-select>
</md-input-container>
Floating label is correct at initialization but when clicking on the empty element the floating label is still up. I also tried with ng-value="undefined" or null and it does not solve it... It seems that the md-select is in a "selected empty value" state which is semantically different from the "back to untouched" state
I'm facing the same issue that @jpolo said. Floating label does not work correctly with this solution.
@jpolo I think what @ThomasBurleson mentioned is you need to have a dropdown option with blank value and value (in controller) should be set to blank instead of setting to null or undefined as HTML treats a blank value dropdown as required and won't allow user to submit form until value is selected.
Are you suggesting my issue should go in a new issue or what should I do concerning this issue?
I'm facing the same issue and I use as a fix :
<md-input-container ng-class="{ 'md-undefined-select': !myModel }">
<label>My Label</label>
<md-select ng-model="myModel">
<md-option value="undefined"></md-option>
<md-option ng-repeat="(key, value) in values" ng-value="key">{{ value }}</md-option>
</md-select>
</md-input-container>
And CSS:
.md-undefined-select {
label {
transform: translate3d(0, 28px, 0) scale(1) !important;
color: rgba(0,0,0,0.26) !important;
}
}
It's unorthodox , but this helps me.
Not sure why this isn't supported yet, but here is a hack
HTML
<md-input-container flex="30">
<label>Account</label>
<md-select ng-model="product.account">
<md-option class="empty-value"></md-option>
<md-option>Cash</md-option>
<md-option>Bank</md-option>
</select>
</md-input-container>
CSS (Sass):
md-option
&.empty-value
.md-text:after
content: '- SELECT -'
@raduburcuta @sheaujye your approaches won't if you use placeholder.
bump -ish
New to md and am experiencing this issue also. Is there a solution? The ad-hoc solution is awesome but doesn't address the issue.
@jayeshanandani suggests
you need to have a dropdown option with blank value and value (in controller)
Can someone explain like I'm 5 what he means?
<label>Status <small>Note: <b style="color:red;">Highlighted content</b></small></label>
<md-select ng-value="{{marital_status}}" ng-model="marital_status" name="marital_status" id="marital_status">
<md-option value=""></md-option> <!-- hack see css -->
<md-option>SINGLE</md-option>
<md-option>MARRIED</md-option>
<md-option>DIVORCED</md-option>
<md-option>WIDOWED</md-option>
<md-option>SEPARATED</md-option>
</md-select>
@dreaddy : Thomas states that standard HTML way to clear select is to add blank option. That is the same thing I suggested that if you are repeating a md-option loop you just need to add:
<md-option value="">Please Select</md-option>
This option ensures and also helps the user to revert back to a blank value.
@jayeshanandani Thank you much.