>>>ngCloak shouldn't be a factor.
>>>
>>>ng-show expects a bool and 'BirthDate' returns a string although, since it appears that the label is showing, that's probably not the root of the problem.
>>>
>>>I'd suspect that having ' ng-model="currentData.birthDate" ' and ' data-date-change="birthDateChange" ' (which can also set 'currentData.birthDate) on the datepicker may be the problem - it could be causing multiple digest cycles.
>>>
>>
>>The smDateTimePicker directive itself sets the model, etc. so perhaps this is also a factor. I think I'm going to live with that delay, it is not an end of the world.
>
>Is that your own directive? How does it know there's a 'birthDateChange' method available ?
>
>Seems to me that unless you correct the problem then it will exist anywhere that directive is used ?
I think the issue is similar to VFP / Valid or LostFocus. So, if I change the date using Calendar or type something - the age changes right away. However, if I just clear the date and not remove the focus from the field, it takes about 30 sec. before form refreshes itself and age disappears.
If after clearing I click in another input control, the age immediately disappears.
So, I just need to somehow "simulate" that click right after I cleared that text.
Also, looking closer into the code I see that some action is done when the value is not empty, but nothing when the value is empty - can it be my problem?
/**
* @param {ng.IScope} scope
* @param {jquery} element
* @param {ng.IAttributes} attrs
* @param {Array<ng.IFormController>} ctrls
*/
var link = function(scope, element, attrs, ctrls) {
let vm = ctrls[0];
let ngModelCtrl = ctrls[1];
let input = element.find("input");
var listener = scope.$watch("vm.ngModel",
function(value) {
if (value) {
if (!vm.isTimeOnly()) {
vm.Options.defaultDate = vm.Options.viewDate = vm.Options.date = moment(value);
}
if (!_.isUndefined(vm.datetimepicker)) {
vm.datetimepicker.data("DateTimePicker").destroy();
vm.datetimepicker = undefined;
}
vm.datetimepicker = element.find(".input-group").datetimepicker(vm.Options);
if (moment.isMoment(value)) {
vm.Model = value;
} else if (!vm.isTimeOnly()) {
vm.Model = moment(value);
} else {
let temp = moment();
let time = value.split(':');
temp.set({ hour: time[0], minute: time[1], second: 0, millisecond: 0 });
vm.Model = temp;
}
vm.HasInitialValueChanged = true;
input.val(vm.Model.format(vm.FORMAT));
listener();
}
});
vm.datetimepicker = element.find(".input-group").datetimepicker(vm.Options);
vm.datetimepicker.on("dp.change", _.curry(link.onDateTimePickerChange.bind(vm))(ngModelCtrl));
input.on("blur", _.curry(link.onBlur.bind(vm))(input)(ngModelCtrl));
If it's not broken, fix it until it is.
My Blog