Skip to content

Commit

Permalink
LPS-84020 Fix datepicker behaviour when it is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
camisLuisa authored and brianchandotcom committed Aug 24, 2018
1 parent 72477cf commit 663c87c
Showing 1 changed file with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ AUI.add(
if (calendar.get('boundingBox').contains(node) || popover.get('visible')) {
hasFocus = true;
}

}

return hasFocus;
Expand All @@ -128,7 +129,7 @@ AUI.add(

var element = instance.getTriggerNode().getDOM();

DDMDate.vanillaTextMask(
instance.dateMask = DDMDate.vanillaTextMask(
{
inputElement: element,
mask: [/\d/, /\d/, '/', /\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/],
Expand All @@ -145,6 +146,9 @@ AUI.add(
after: {
selectionChange: A.bind('_afterSelectionChange', instance)
},
on: {
selectionChange: A.bind('_onSelectionChange', instance)
},
mask: instance.get('mask'),
popover: {
zIndex: Liferay.zIndex.TOOLTIP
Expand All @@ -153,6 +157,8 @@ AUI.add(
}
);

instance.datePicker.getCalendar().on('dateClick', instance._onDateClick.bind(this));

return instance;
},

Expand Down Expand Up @@ -180,11 +186,49 @@ AUI.add(
formGroup.append(container.one('.form-feedback-item'));
},

_afterSelectionChange: function(event) {
_getDatePlaceholder: function() {
var instance = this;

if (instance.dateMask) {
return instance.dateMask.textMaskInputElement.state.previousPlaceholder;
}
},

_onSelectionChange: function(event) {
var instance = this;

if (!instance.getTriggerNode().val() || (instance.getTriggerNode().val() == instance._getDatePlaceholder())) {
instance.invalidValue = true;
}
},

_afterSelectionChange: function(event) {
var instance = this;
var date = event.newSelection;

instance.dateValue = instance.getTriggerNode().val()

if (instance.invalidValue) {
return instance.clearDateInputValue();
}

return instance._setDatePickerValue(date);
},

clearDateInputValue: function() {
instance = this;

var placeholder = instance._getDatePlaceholder();

instance.getTriggerNode().val('');
instance.getTriggerNode().setAttribute('placeholder', placeholder)
instance.setValue('');
instance.invalidValue = false;
},

_setDatePickerValue: function(date) {
var instance = this;

if (isArray(date) && date.length) {
date = date[0];
}
Expand All @@ -194,6 +238,8 @@ AUI.add(
instance.validate();

instance._fireStartedFillingEvent();

instance.actionByCalendar = false;
},

_onBlurInput: function() {
Expand Down Expand Up @@ -224,6 +270,13 @@ AUI.add(
instance.getTriggerNode().focus();

datePicker.show();
},

_onDateClick: function(event) {
var instance = this;

instance.getTriggerNode().val(instance.dateValue);
instance._setDatePickerValue(event.date);
}
}
}
Expand Down

0 comments on commit 663c87c

Please sign in to comment.