var MonthIndex = [
{
Name: "January",
MaxDays: 31,
DataValue:'01'
},
{
Name: "February",
MaxDays: 29,
DataValue: '02'
},
{
Name: "March",
MaxDays: 31,
DataValue: '03'
},
{
Name: "April",
MaxDays: 30,
DataValue: '04'
},
{
Name: "May",
MaxDays: 31,
DataValue: '05'
},
{
Name: "June",
MaxDays: 30,
DataValue: '06'
},
{
Name: "July",
MaxDays: 31,
DataValue: '07'
},
{
Name: "August",
MaxDays: 31,
DataValue: '08'
},
{
Name: "September",
MaxDays: 30,
DataValue: '09'
},
{
Name: "October",
MaxDays: 31,
DataValue: '10'
},
{
Name: "November",
MaxDays: 30,
DataValue: '11'
},
{
Name: "December",
MaxDays: 31,
DataValue: '12'
}
];
(function(){
var app = angular.module('FormFields', []);
app.controller('formController', ['$scope', function($scope){
var disabled = this.formDisabled;
disabled = 'disabled';
this.monthIndex = MonthIndex;
this.required = function(field, skipEmptyCheck){
var form = $('[name="' + field + '"]').closest('form').attr('name'), emptyCheck = '',
status = '';
if (skipEmptyCheck){
status = (eval('$scope.' +form + '.' + field + '.$pristine'));
} else {
status = (eval('$scope.' +form + '.' + field + '.$pristine && !$scope.' + form + '.' + field + '.$viewValue'));
}
return(status);
};
this.invalid = function(field){
var form = $('[name="' + field + '"]').closest('form').attr('name'),
status = eval('$scope.' + form + '.' + field + '.$invalid && !$scope.' + form + '.' + field + '.$pristine');
if (status){
$('[name="' + field + '"]').parent().find('.input-group-addon').removeClass('valid').addClass('invalid');
return(true);
} else {
$('[name="' + field + '"]').parent().find('.input-group-addon').removeClass('invalid');
return(false);
}
}
this.valid = function(field){
var form = $('[name="' + field + '"]').closest('form').attr('name'),
status = eval('$scope.' + form + '.' + field + '.$valid && !$scope.' + form + '.' + field + '.$pristine && $scope.' + form + '.' + field + '.$viewValue') ;
if (status){
$('[name="' + field + '"]').parent().find('.input-group-addon').removeClass('invalid').addClass('valid');
return(true);
} else {
$('[name="' + field + '"]').parent().find('.input-group-addon').removeClass('valid');
return(false);
}
}
this.disabled = function(field){
var form = $('[name="' + field + '"]').closest('form').attr('name'),
status = $('[name="' + field + '"]').attr('disabled');
if (status){
$('[name="' + field + '"]').parent().find('.input-group-addon').removeClass('valid').addClass('invalid');
return(true);
}
}
this.updateDaysInMonth = function(monthField,dayField){
var i = 1, tempStorage = [],
totalDays = parseInt($('[name="' + monthField.$name + '"] option:selected').attr('daysInMoth')) + 1;
if (totalDays > 0){
$('[name="' + dayField.$name +'"]').html('').attr('disabled', false);
} else {
$('[name="' + dayField.$name +'"]').html('').attr('disabled', true);
}
while (i < totalDays) {
var makeItRight = '';
if (i < 10) {
makeItRight = '0';
}
if (i == dayField.$modelValue) {
$('[name="' + dayField.$name +'"]').append('');
} else {
$('[name="' + dayField.$name + '"]').append('');
}
i++;
}
console.log(dayField.$modelValue)
}
}]);
app.directive('fieldMatch', function(){
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
var targetField = '[name="' + attrs.fieldMatch + '"]';
elem.add(targetField).on('keyup', function () {
scope.$apply(function () {
// console.info(elem.val() === $(targetField).val());
console.log(elem.val() === $(targetField).val())
ctrl.$setValidity('fieldmatch', elem.val() === $(targetField).val());
});
});
}
};
});
app.directive('fieldCombine', function(){
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
var targetFields = eval(attrs.fieldCombine);
}
};
});
app.directive('statusInvalid', function(){
return {
restrict: 'E',
template: ' Invalid'
}
});
app.directive('statusValid', function(){
return {
restrict: 'E',
template: ''
}
});
app.directive('statusRequired', function(){
return {
restrict: 'E',
template: ''
}
});
})();