From fe296abfd536f666c6a2475e0dd51c624eaa8020 Mon Sep 17 00:00:00 2001 From: Bruno Basto Date: Wed, 22 Aug 2018 14:28:06 -0300 Subject: [PATCH] LPS-84020 SF --- .../META-INF/resources/date/date_field.js | 93 ++++++++++--------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-field-type/src/main/resources/META-INF/resources/date/date_field.js b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-field-type/src/main/resources/META-INF/resources/date/date_field.js index ac45b281cd9c24..7f055e30f2efd3 100644 --- a/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-field-type/src/main/resources/META-INF/resources/date/date_field.js +++ b/modules/apps/dynamic-data-mapping/dynamic-data-mapping-form-field-type/src/main/resources/META-INF/resources/date/date_field.js @@ -46,6 +46,18 @@ AUI.add( } }, + clearDateInputValue: function() { + var instance = this; + var placeholder = instance._getDatePlaceholder(); + var triggerNode = instance.getTriggerNode(); + + triggerNode.setAttribute('placeholder', placeholder); + triggerNode.val(''); + + instance.setValue(''); + instance.invalidValue = false; + }, + formatDate: function(isoDate) { var instance = this; @@ -108,7 +120,6 @@ AUI.add( if (calendar.get('boundingBox').contains(node) || popover.get('visible')) { hasFocus = true; } - } return hasFocus; @@ -146,10 +157,10 @@ AUI.add( after: { selectionChange: A.bind('_afterSelectionChange', instance) }, + mask: instance.get('mask'), on: { selectionChange: A.bind('_onSelectionChange', instance) }, - mask: instance.get('mask'), popover: { zIndex: Liferay.zIndex.TOOLTIP }, @@ -186,60 +197,31 @@ AUI.add( formGroup.append(container.one('.form-feedback-item')); }, - _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() + instance.dateValue = instance.getTriggerNode().val(); if (instance.invalidValue) { - return instance.clearDateInputValue(); + instance.clearDateInputValue(); + } + else { + instance._setDatePickerValue(date); } - - 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) { + _getDatePlaceholder: function() { var instance = this; - if (isArray(date) && date.length) { - date = date[0]; - } - - instance.setValue(instance.getISODate(date)); - - instance.validate(); + var placeholder = null; - instance._fireStartedFillingEvent(); + if (instance.dateMask) { + placeholder = instance.dateMask.textMaskInputElement.state.previousPlaceholder; + } - instance.actionByCalendar = false; + return placeholder; }, _onBlurInput: function() { @@ -277,6 +259,31 @@ AUI.add( instance.getTriggerNode().val(instance.dateValue); instance._setDatePickerValue(event.date); + }, + + _onSelectionChange: function(event) { + var instance = this; + var triggerNode = instance.getTriggerNode(); + var value = triggerNode.val(); + + if (!value || (value == instance._getDatePlaceholder())) { + instance.invalidValue = true; + } + }, + + _setDatePickerValue: function(date) { + var instance = this; + + if (isArray(date) && date.length) { + date = date[0]; + } + + instance.setValue(instance.getISODate(date)); + instance.validate(); + + instance._fireStartedFillingEvent(); + + instance.actionByCalendar = false; } } }