Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 9666c64

Browse files
bifoduswesleycho
authored andcommittedSep 25, 2016
feat(timepicker): add validation information
- Add validation information for specific violations, allowing users to style classes generated by Angular Closes #6230 Closes #6259
1 parent f9f7e02 commit 9666c64

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

Diff for: ‎src/timepicker/test/timepicker.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ describe('timepicker directive', function() {
12301230
changeInputValueTo(el, 'pizza');
12311231
expect($rootScope.time).toBe(null);
12321232
expect(el.parent().hasClass('has-error')).toBe(true);
1233+
expect(el.hasClass('ng-invalid-hours'));
12331234
expect(element.hasClass('ng-invalid-time')).toBe(true);
12341235

12351236
changeInputValueTo(el, 8);
@@ -1247,6 +1248,7 @@ describe('timepicker directive', function() {
12471248
changeInputValueTo(el, '8a');
12481249
expect($rootScope.time).toBe(null);
12491250
expect(el.parent().hasClass('has-error')).toBe(true);
1251+
expect(el.hasClass('ng-invalid-minutes'));
12501252
expect(element.hasClass('ng-invalid-time')).toBe(true);
12511253

12521254
changeInputValueTo(el, 22);
@@ -1262,6 +1264,7 @@ describe('timepicker directive', function() {
12621264
changeInputValueTo(el, 'pizza');
12631265
expect($rootScope.time).toBe(null);
12641266
expect(el.parent().hasClass('has-error')).toBe(true);
1267+
expect(el.hasClass('ng-invalid-seconds'));
12651268
expect(element.hasClass('ng-invalid-time')).toBe(true);
12661269

12671270
changeInputValueTo(el, 13);
@@ -1291,6 +1294,9 @@ describe('timepicker directive', function() {
12911294
elS.blur();
12921295
$rootScope.$digest();
12931296

1297+
expect(elH.hasClass('ng-valid'));
1298+
expect(elM.hasClass('ng-valid'));
1299+
expect(elS.hasClass('ng-valid'));
12941300
expect(element.hasClass('ng-invalid-time')).toBe(false);
12951301
});
12961302

Diff for: ‎src/timepicker/timepicker.js

+26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ angular.module('ui.bootstrap.timepicker', [])
1515
})
1616

1717
.controller('UibTimepickerController', ['$scope', '$element', '$attrs', '$parse', '$log', '$locale', 'uibTimepickerConfig', function($scope, $element, $attrs, $parse, $log, $locale, timepickerConfig) {
18+
var hoursModelCtrl, minutesModelCtrl, secondsModelCtrl;
1819
var selected = new Date(),
1920
watchers = [],
2021
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl
@@ -36,6 +37,10 @@ angular.module('ui.bootstrap.timepicker', [])
3637
minutesInputEl = inputs.eq(1),
3738
secondsInputEl = inputs.eq(2);
3839

40+
hoursModelCtrl = hoursInputEl.controller('ngModel');
41+
minutesModelCtrl = minutesInputEl.controller('ngModel');
42+
secondsModelCtrl = secondsInputEl.controller('ngModel');
43+
3944
var mousewheel = angular.isDefined($attrs.mousewheel) ? $scope.$parent.$eval($attrs.mousewheel) : timepickerConfig.mousewheel;
4045

4146
if (mousewheel) {
@@ -295,14 +300,23 @@ angular.module('ui.bootstrap.timepicker', [])
295300
ngModelCtrl.$setValidity('time', false);
296301
if (angular.isDefined(invalidHours)) {
297302
$scope.invalidHours = invalidHours;
303+
if (hoursModelCtrl) {
304+
hoursModelCtrl.$setValidity('hours', false);
305+
}
298306
}
299307

300308
if (angular.isDefined(invalidMinutes)) {
301309
$scope.invalidMinutes = invalidMinutes;
310+
if (minutesModelCtrl) {
311+
minutesModelCtrl.$setValidity('minutes', false);
312+
}
302313
}
303314

304315
if (angular.isDefined(invalidSeconds)) {
305316
$scope.invalidSeconds = invalidSeconds;
317+
if (secondsModelCtrl) {
318+
secondsModelCtrl.$setValidity('seconds', false);
319+
}
306320
}
307321
};
308322

@@ -425,6 +439,18 @@ angular.module('ui.bootstrap.timepicker', [])
425439
}
426440

427441
function makeValid() {
442+
if (hoursModelCtrl) {
443+
hoursModelCtrl.$setValidity('hours', true);
444+
}
445+
446+
if (minutesModelCtrl) {
447+
minutesModelCtrl.$setValidity('minutes', true);
448+
}
449+
450+
if (secondsModelCtrl) {
451+
secondsModelCtrl.$setValidity('seconds', true);
452+
}
453+
428454
ngModelCtrl.$setValidity('time', true);
429455
$scope.invalidHours = false;
430456
$scope.invalidMinutes = false;

0 commit comments

Comments
 (0)
This repository has been archived.