Skip to content

Commit

Permalink
fixed issue edit pattern not applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Gulshan Mishra committed Jan 5, 2024
1 parent 53de10c commit d848697
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(function() {

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

static NS = FormView.Constants.NS;
static IS = "adaptiveFormDatePicker";
Expand Down Expand Up @@ -64,6 +64,7 @@
if (this.isActive()) {
this.widgetObject.setValue(value);
} else {
this._model.value = this.widgetObject.getValue();
this.widgetObject.setDisplayValue(value);
}
} else {
Expand All @@ -78,10 +79,10 @@
this.widgetObject = new DatePickerWidget(this, this.getWidget(), model);
}
if (this.widgetObject.getValue() !== '') {
this._model.value = this.widgetObject.getValue();
super.updateFormattedDate(this.widgetObject.getValue());
}
this.widgetObject.addEventListener('blur', (e) => {
this._model.value = this.widgetObject.getValue();
super.updateFormattedDate(e.target.value);

//setDisplayValue is required for cases where value remains same while focussing in and out.
this.widgetObject.setDisplayValue(this._model.value);
Expand Down
4 changes: 2 additions & 2 deletions ui.frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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, FormCheckBox, FormOptionFieldBase} from "./view/index.js";
import {FormField, FormContainer, FormFieldBase, FormPanel, FormTabs, FormCheckBox, FormOptionFieldBase, FormDatePicker} from "./view/index.js";
import {Constants} from "./constants.js";
import GuideBridge from "./GuideBridge.js";
import HTTPAPILayer from "./HTTPAPILayer.js";
Expand Down Expand Up @@ -77,4 +77,4 @@ const FileAttachmentUtils = {
*/


export {createFormInstance, FormTabs, FormField, FormFieldBase, FormPanel, FormContainer, Constants, Utils, Actions, HTTPAPILayer, FileAttachmentUtils, Formatters, LanguageUtils, FunctionRuntime, FormCheckBox, FormOptionFieldBase};
export {createFormInstance, FormTabs, FormField, FormFieldBase, FormPanel, FormContainer, Constants, Utils, Actions, HTTPAPILayer, FileAttachmentUtils, Formatters, LanguageUtils, FunctionRuntime, FormCheckBox, FormOptionFieldBase, FormDatePicker};
46 changes: 46 additions & 0 deletions ui.frontend/src/view/FormDatePicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright 2024 Adobe
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

import FormFieldBase from "./FormFieldBase.js";
import {parse} from "@aemforms/af-formatters";

/**
* Class representing Date picker.
* @extends module:FormView~FormDatePicker
*/
class FormDatePicker extends FormFieldBase {

constructor(params) {
super(params);
}

updateFormattedDate(value){
this._model.value = this.formatDate(value);
}

formatDate(value) {
const currDate = parse(value.toString(), this._model.locale, this._model.editFormat, null, false);
if (currDate && !isNaN(currDate) && value != null) {
this.selectedMonth = currDate.getMonth();
this.selectedYear = currDate.getFullYear();
this.selectedDay = currDate.getDate();
return this.selectedYear + "-" + (this.selectedMonth + 1) +"-"+ this.selectedDay + "";
} else return value;
}

}

export default FormDatePicker;
3 changes: 2 additions & 1 deletion ui.frontend/src/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import FormPanel from "./FormPanel.js";
import FormTabs from "./FormTabs.js";
import FormCheckBox from "./FormCheckBox.js";
import FormOptionFieldBase from "./FormOptionFieldBase";
import FormDatePicker from "./FormDatePicker";


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

0 comments on commit d848697

Please sign in to comment.