Skip to content

Commit

Permalink
fix(input): remove unnecessary warnings when ng-messages not provided
Browse files Browse the repository at this point in the history
There is no requirement to include the messages in case of an error.
Highlighting the field can be enough.

Fixes angular#10461
  • Loading branch information
marosoft committed Jun 29, 2018
1 parent 3660a32 commit 1eed52d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 77 deletions.
52 changes: 0 additions & 52 deletions src/components/input/input-animations.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,58 +90,6 @@ describe('md-input-container animations', function() {

describe('method tests', function() {

describe('#showInputMessages', function() {
it('logs a warning with no messages element', inject(function($log) {
// Note that the element does NOT have a parent md-input-messages-animation class
var element = angular.element('<div><div class="md-input-message-animation"></div></div>');
var done = jasmine.createSpy('done');
var warnSpy = spyOn($log, 'warn');

$$mdInput.messages.show(element, done);

expect(done).toHaveBeenCalled();
expect(warnSpy).toHaveBeenCalled();
}));

it('logs a warning with no messages children', inject(function($log) {
// Note that the element does NOT have any child md-input-message-animation divs
var element = angular.element('<div class="md-input-messages-animation"></div>');
var done = jasmine.createSpy('done');
var warnSpy = spyOn($log, 'warn');

$$mdInput.messages.show(element, done);

expect(done).toHaveBeenCalled();
expect(warnSpy).toHaveBeenCalled();
}));
});

describe('#hideInputMessages', function() {
it('logs a warning with no messages element', inject(function($log) {
// Note that the element does NOT have a parent md-input-messages-animation class
var element = angular.element('<div><div class="md-input-message-animation"></div></div>');
var done = jasmine.createSpy('done');
var warnSpy = spyOn($log, 'warn');

$$mdInput.messages.hide(element, done);

expect(done).toHaveBeenCalled();
expect(warnSpy).toHaveBeenCalled();
}));

it('logs a warning with no messages children', inject(function($log) {
// Note that the element does NOT have any child md-input-message-animation divs
var element = angular.element('<div class="md-input-messages-animation"></div>');
var done = jasmine.createSpy('done');
var warnSpy = spyOn($log, 'warn');

$$mdInput.messages.hide(element, done);

expect(done).toHaveBeenCalled();
expect(warnSpy).toHaveBeenCalled();
}));
});

describe('#getMessagesElement', function() {

it('finds the messages element itself', function() {
Expand Down
33 changes: 8 additions & 25 deletions src/components/input/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ if (window._mdMocksIncluded) {
return {
// special accessor to internals... useful for testing
messages: {
show : showInputMessages,
hide : hideInputMessages,
getElement : getMessagesElement
}
};
Expand Down Expand Up @@ -942,10 +940,10 @@ function ngMessageDirective($mdUtil) {
}
}

var $$AnimateRunner, $animateCss, $mdUtil, $log;
var $$AnimateRunner, $animateCss, $mdUtil;

function mdInputInvalidMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil, $log) {
saveSharedServices($$AnimateRunner, $animateCss, $mdUtil, $log);
function mdInputInvalidMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil) {
saveSharedServices($$AnimateRunner, $animateCss, $mdUtil);

return {
addClass: function(element, className, done) {
Expand All @@ -956,8 +954,8 @@ function mdInputInvalidMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil,
};
}

function ngMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil, $log) {
saveSharedServices($$AnimateRunner, $animateCss, $mdUtil, $log);
function ngMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil) {
saveSharedServices($$AnimateRunner, $animateCss, $mdUtil);

return {
enter: function(element, done) {
Expand Down Expand Up @@ -1007,15 +1005,8 @@ function ngMessageAnimation($$AnimateRunner, $animateCss, $mdUtil, $log) {
function showInputMessages(element, done) {
var animators = [], animator;
var messages = getMessagesElement(element);
var children = messages.children();

if (messages.length == 0 || children.length == 0) {
$log.warn('mdInput messages show animation called on invalid messages element: ', element);
done();
return;
}

angular.forEach(children, function(child) {
angular.forEach(messages.children(), function(child) {
animator = showMessage(angular.element(child));

animators.push(animator.start());
Expand All @@ -1027,15 +1018,8 @@ function showInputMessages(element, done) {
function hideInputMessages(element, done) {
var animators = [], animator;
var messages = getMessagesElement(element);
var children = messages.children();

if (messages.length == 0 || children.length == 0) {
$log.warn('mdInput messages hide animation called on invalid messages element: ', element);
done();
return;
}

angular.forEach(children, function(child) {
angular.forEach(messages.children(), function(child) {
animator = hideMessage(angular.element(child));

animators.push(animator.start());
Expand Down Expand Up @@ -1110,9 +1094,8 @@ function getMessagesElement(element) {
return angular.element(element[0].querySelector('.md-input-messages-animation'));
}

function saveSharedServices(_$$AnimateRunner_, _$animateCss_, _$mdUtil_, _$log_) {
function saveSharedServices(_$$AnimateRunner_, _$animateCss_, _$mdUtil_) {
$$AnimateRunner = _$$AnimateRunner_;
$animateCss = _$animateCss_;
$mdUtil = _$mdUtil_;
$log = _$log_;
}

0 comments on commit 1eed52d

Please sign in to comment.