MCPcopy Create free account
hub / github.com/cafebazaar/blacksmith / createDateInputType

Function createDateInputType

web/static/bower_components/angular/angular.js:21812–21882  ·  view source on GitHub ↗
(type, regexp, parseDate, format)

Source from the content-addressed store, hash-verified

21810}
21811
21812function createDateInputType(type, regexp, parseDate, format) {
21813 return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) {
21814 badInputChecker(scope, element, attr, ctrl);
21815 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
21816 var timezone = ctrl && ctrl.$options && ctrl.$options.timezone;
21817 var previousDate;
21818
21819 ctrl.$$parserName = type;
21820 ctrl.$parsers.push(function(value) {
21821 if (ctrl.$isEmpty(value)) return null;
21822 if (regexp.test(value)) {
21823 // Note: We cannot read ctrl.$modelValue, as there might be a different
21824 // parser/formatter in the processing chain so that the model
21825 // contains some different data format!
21826 var parsedDate = parseDate(value, previousDate);
21827 if (timezone) {
21828 parsedDate = convertTimezoneToLocal(parsedDate, timezone);
21829 }
21830 return parsedDate;
21831 }
21832 return undefined;
21833 });
21834
21835 ctrl.$formatters.push(function(value) {
21836 if (value && !isDate(value)) {
21837 throw ngModelMinErr('datefmt', 'Expected `{0}` to be a date', value);
21838 }
21839 if (isValidDate(value)) {
21840 previousDate = value;
21841 if (previousDate && timezone) {
21842 previousDate = convertTimezoneToLocal(previousDate, timezone, true);
21843 }
21844 return $filter('date')(value, format, timezone);
21845 } else {
21846 previousDate = null;
21847 return '';
21848 }
21849 });
21850
21851 if (isDefined(attr.min) || attr.ngMin) {
21852 var minVal;
21853 ctrl.$validators.min = function(value) {
21854 return !isValidDate(value) || isUndefined(minVal) || parseDate(value) >= minVal;
21855 };
21856 attr.$observe('min', function(val) {
21857 minVal = parseObservedDateValue(val);
21858 ctrl.$validate();
21859 });
21860 }
21861
21862 if (isDefined(attr.max) || attr.ngMax) {
21863 var maxVal;
21864 ctrl.$validators.max = function(value) {
21865 return !isValidDate(value) || isUndefined(maxVal) || parseDate(value) <= maxVal;
21866 };
21867 attr.$observe('max', function(val) {
21868 maxVal = parseObservedDateValue(val);
21869 ctrl.$validate();

Callers 1

angular.jsFile · 0.85

Calls 8

badInputCheckerFunction · 0.85
baseInputTypeFunction · 0.85
convertTimezoneToLocalFunction · 0.85
isDateFunction · 0.85
isValidDateFunction · 0.85
isDefinedFunction · 0.85
isUndefinedFunction · 0.85
parseObservedDateValueFunction · 0.85

Tested by

no test coverage detected