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

Commit

Permalink
fix(input): check invalid model immediately and setInvalid() if needed
Browse files Browse the repository at this point in the history
Closes #372.
  • Loading branch information
ThomasBurleson committed Feb 9, 2015
1 parent 1c2884d commit e0f53dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,6 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) {
setupTextarea();
}

function ngModelPipelineCheckValue(arg) {
containerCtrl.setHasValue(!ngModelCtrl.$isEmpty(arg));
return arg;
}
function inputCheckValue() {
// An input's value counts if its length > 0,
// or if the input's validity state says it has bad input (eg string in a number input)
containerCtrl.setHasValue(element.val().length > 0 || (element[0].validity||{}).badInput);
}


var isErrorGetter = containerCtrl.isErrorGetter || function() {
return ngModelCtrl.$invalid && ngModelCtrl.$touched;
};
Expand All @@ -222,6 +211,9 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) {
containerCtrl.setFocused(false);
inputCheckValue();
});

ngModelCtrl.$setTouched();
if( ngModelCtrl.$invalid ) containerCtrl.setInvalid();
}

scope.$on('$destroy', function() {
Expand All @@ -230,6 +222,19 @@ function inputTextareaDirective($mdUtil, $window, $compile, $animate) {
containerCtrl.input = null;
});

/**
*
*/
function ngModelPipelineCheckValue(arg) {
containerCtrl.setHasValue(!ngModelCtrl.$isEmpty(arg));
return arg;
}
function inputCheckValue() {
// An input's value counts if its length > 0,
// or if the input's validity state says it has bad input (eg string in a number input)
containerCtrl.setHasValue(element.val().length > 0 || (element[0].validity||{}).badInput);
}

function setupTextarea() {
var node = element[0];
var onChangeTextarea = $mdUtil.debounce(growTextarea, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/js/tabItemDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ angular.module('material.components.tabs')
* @restrict E
*
* @description
* `<md-tab>` is the nested directive used [within `<md-tabs>`] to specify each tab with a **label** and optional *view content*.
* Use the `<md-tab>` a nested directive used within `<md-tabs>` to specify a tab with a **label** and optional *view content*.
*
* If the `label` attribute is not specified, then an optional `<md-tab-label>` tag can be used to specify more
* complex tab header markup. If neither the **label** nor the **md-tab-label** are specified, then the nested
Expand Down
1 change: 1 addition & 0 deletions src/core/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ angular.module('material.core')
fakeNgModel: function() {
return {
$fake: true,
$setTouched : angular.noop,
$setViewValue: function(value) {
this.$viewValue = value;
this.$render(value);
Expand Down

3 comments on commit e0f53dd

@epelc
Copy link
Contributor

@epelc epelc commented on e0f53dd Feb 12, 2015

Choose a reason for hiding this comment

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

@ThomasBurleson I think this breaks ng-touched and it adds the invalid styles on page load. I opened #1485 with more info.

@ThomasBurleson
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@epelc - how does this break ng-touched?

@epelc
Copy link
Contributor

@epelc epelc commented on e0f53dd Feb 12, 2015

Choose a reason for hiding this comment

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

@ThomasBurleson It's appling ng-touched on page load if your input is required.

For example I haven't touched either one of these(click it for zoomed version)
image

Please sign in to comment.