Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
feat(select): add styles for invalid
Browse files Browse the repository at this point in the history
closes #1843, references #1722, references #1581
  • Loading branch information
rschmukler committed Mar 25, 2015
1 parent e0f9fe9 commit ddf1198
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/input/input-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ md-input-container.md-THEME_NAME-theme {
color: '{{foreground-3}}';
}

div[ng-messages] {
color: '{{warn-500}}'
}


&:not(.md-input-invalid) {
&.md-input-has-value {
Expand Down
4 changes: 2 additions & 2 deletions src/components/input/input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ md-input-container {
}

label:not(.md-no-float),
.md-placeholder {
.md-placeholder:not(.md-select-label) {
order: 1;
pointer-events: none;
-webkit-font-smoothing: antialiased;
Expand All @@ -73,7 +73,7 @@ md-input-container {
transform-origin: left top;
transition: transform $swift-ease-out-timing-function 0.25s;
}
.md-placeholder {
.md-placeholder:not(.md-select-label) {
position: absolute;
top: 0;
opacity: 0;
Expand Down
17 changes: 17 additions & 0 deletions src/components/select/demoValidations/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div ng-app="selectDemoBasic" ng-controller="AppCtrl" layout="column" layout-align="center center" style="min-height: 300px;">
<form name="myForm">
<p>Note that invalid styling only applies if invalid and dirty</p>
<md-input-container>
<md-select name="myModel" placeholder="Pick" ng-model="myModel" required>
<md-option value="1">One</md-option>
<md-option value="2">Two</md-option>
</md-select>
<div class="errors" ng-messages="myForm.myModel.$error" ng-if="myForm.$dirty">
<div ng-message="required">Required</div>
</div>
</md-input-container>
<div layout="row">
<md-button ng-click="clearValue()" ng-disabled="!myModel" style="margin-right: 20px;">Clear</md-button>
<md-button ng-click="save()" ng-disabled="myForm.$invalid" class="md-primary" layout layout-align="center end">Save</md-button>
</div>
</div>
9 changes: 9 additions & 0 deletions src/components/select/demoValidations/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('selectDemoBasic', ['ngMaterial', 'ngMessages'])
.controller('AppCtrl', function($scope) {
$scope.clearValue = function() {
$scope.myModel = undefined;
};
$scope.save = function() {
alert('Form was valid!');
};
});
14 changes: 14 additions & 0 deletions src/components/select/demoValidations/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
p {
padding: 0 20px;
text-align: center;
}

p.result {
font-size: 0.8em;
color: #777;
}


.demo-content {
min-height: 348px;
}
6 changes: 6 additions & 0 deletions src/components/select/select-theme.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
md-select.md-THEME_NAME-theme {
&.ng-invalid.ng-dirty {
.md-select-label {
color: '{{warn-500}}' !important;
border-bottom-color: '{{warn-500}}' !important;
}
}
&:not([disabled]):focus {
.md-select-label {
border-bottom-color: '{{primary-color}}';
Expand Down
6 changes: 6 additions & 0 deletions src/components/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ md-select {
&:hover {
cursor: pointer
}
&.ng-invalid.ng-dirty {
.md-select-label {
padding-bottom: 7px;
border-bottom: 2px solid;
}
}
&:focus {
.md-select-label {
border-bottom: 2px solid;
Expand Down

4 comments on commit ddf1198

@kugler
Copy link

@kugler kugler commented on ddf1198 Apr 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rschmukler I think style for ng-messages should support also ng-messages element and not just attribute.
see https://docs.angularjs.org/api/ngMessages/directive/ngMessages

@ThomasBurleson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kugler - please submit a new issue for your request.

@vbanuelos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rschmukler --
There should be some padding added so both label and error message can be displayed

Error Message active:
image

Error Message inactive:
image

Also, the provided demo only shows the error message if something is selected then cleared. But clicking on it, and not selecting anything doesnt change anything. Removing the ng-if $dirty clears this up.

@vbanuelos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another note, Input doesnt color the placeholder text red:
image

Please sign in to comment.