Skip to content

Commit

Permalink
resolved PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Gulshan Mishra committed Jan 12, 2024
1 parent fcefb12 commit 20b2c94
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 61 deletions.
Expand Up @@ -16,7 +16,7 @@
(function() {

"use strict";
class DatePicker extends FormView.FormDatePicker {
class DatePicker extends FormView.FormFieldBase {

static NS = FormView.Constants.NS;
static IS = "adaptiveFormDatePicker";
Expand Down Expand Up @@ -72,18 +72,32 @@
}
}

getFormattedDate(value) {
if(!value || value.trim() === '') {
return '';
}
let editFormat = this._model.editFormat;
if(editFormat === 'date|short') {
editFormat = 'date|yyyy/mm/dd';
}
let currDate = FormView.Formatters.parse(value.toString(), this._model.locale, editFormat, null, false);
if (currDate && !isNaN(currDate) && value != null) {
return currDate.getFullYear() + "-" + (currDate.getMonth() + 1) +"-"+ currDate.getDate() + "";
} else return value;
}

setModel(model) {
super.setModel(model);
if (!this.#noFormats()) {
if (this.widgetObject == null) {
this.widgetObject = new DatePickerWidget(this, this.getWidget(), model);
}
if (this.widgetObject.getValue() !== '') {
super.updateFormattedDate(this.widgetObject.getValue());
this._model.value = this.getFormattedDate(this.widgetObject.getValue());
}
this.widgetObject.addEventListener('blur', (e) => {
const {target:{value}} = e;
super.updateFormattedDate(value);
this._model.value = this.getFormattedDate(value);

//setDisplayValue is required for cases where value remains same while focussing in and out.
this.widgetObject.setDisplayValue(value);
Expand Down
8 changes: 4 additions & 4 deletions ui.frontend/src/index.js
Expand Up @@ -16,11 +16,11 @@
import Utils from "./utils.js";
import LanguageUtils from "./LanguageUtils.js";
import {createFormInstance, FileObject, extractFileInfo, Click, Change, Submit, Blur, AddItem, RemoveItem, CustomEvent} from "@aemforms/af-core";
import {FormField, FormContainer, FormFieldBase, FormPanel, FormTabs, FormFileInput, FormOptionFieldBase, FormCheckBox, FormFileInputWidget, FormDatePicker} from "./view/index.js";
import {FormField, FormContainer, FormFieldBase, FormPanel, FormTabs, FormFileInput, FormOptionFieldBase, FormCheckBox, FormFileInputWidget} from "./view/index.js";
import {Constants} from "./constants.js";
import GuideBridge from "./GuideBridge.js";
import HTTPAPILayer from "./HTTPAPILayer.js";
import {formatDate, parseDate} from "@aemforms/af-formatters";
import {formatDate, parseDate, parse} from "@aemforms/af-formatters";
import {FunctionRuntime} from '@aemforms/af-core';

/**
Expand Down Expand Up @@ -57,7 +57,7 @@ const Actions = {
* @property {function} parseDate - The function for parsing a date.
*/
const Formatters = {
formatDate, parseDate
formatDate, parseDate, parse
}

/**
Expand All @@ -77,4 +77,4 @@ const FileAttachmentUtils = {
*/


export {createFormInstance, FormTabs, FormField, FormFieldBase, FormPanel, FormContainer, Constants, Utils, Actions, HTTPAPILayer, FileAttachmentUtils, Formatters, LanguageUtils, FunctionRuntime, FormCheckBox, FormOptionFieldBase, FormFileInput, FormFileInputWidget, FormDatePicker};
export {createFormInstance, FormTabs, FormField, FormFieldBase, FormPanel, FormContainer, Constants, Utils, Actions, HTTPAPILayer, FileAttachmentUtils, Formatters, LanguageUtils, FunctionRuntime, FormCheckBox, FormOptionFieldBase, FormFileInput, FormFileInputWidget};
52 changes: 0 additions & 52 deletions ui.frontend/src/view/FormDatePicker.js

This file was deleted.

3 changes: 1 addition & 2 deletions ui.frontend/src/view/index.js
Expand Up @@ -22,7 +22,6 @@ import FormCheckBox from "./FormCheckBox.js";
import FormFileInput from "./FormFileInput.js";
import FormFileInputWidget from "./FormFileInputWidget.js";
import FormOptionFieldBase from "./FormOptionFieldBase";
import FormDatePicker from "./FormDatePicker";


export {FormField, FormContainer, FormFieldBase, FormPanel, FormTabs, FormCheckBox, FormOptionFieldBase, FormFileInput, FormFileInputWidget, FormDatePicker }
export {FormField, FormContainer, FormFieldBase, FormPanel, FormTabs, FormCheckBox, FormOptionFieldBase, FormFileInput, FormFileInputWidget }

0 comments on commit 20b2c94

Please sign in to comment.