diff --git a/package.json b/package.json index f8212b7..22e29b7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "uglify-js": "^3.13.9", "uglifyjs-webpack-plugin": "^2.2.0", "webpack": "^5.38.1", - "webpack-cli": "^4.7.0", + "webpack-cli": "^4.7.2", "webpack-dev-server": "^3.11.2" } } diff --git a/src/common/core/BaseElement/BaseElement.ts b/src/common/core/BaseElement/BaseElement.ts index 163694b..81d2249 100644 --- a/src/common/core/BaseElement/BaseElement.ts +++ b/src/common/core/BaseElement/BaseElement.ts @@ -9,6 +9,7 @@ class BaseElement extends HTMLElement { private _appMain: AppMainElement; public loader: Loader; public elementDisconnectCallbacks: Array = []; + public initialized: boolean = false; constructor() { super(); this.connectedCallback = this.connectedCallback.bind(this); @@ -86,6 +87,7 @@ class BaseElement extends HTMLElement { this.bindEvents('data-action'); this.bindEvents('app-action'); this.updateCallback(); + this.initialized = true; }; connectedCallback(): void { diff --git a/src/common/pages/BasePageElement/BasePageElement.ts b/src/common/pages/BasePageElement/BasePageElement.ts index c0859e1..c13dedd 100644 --- a/src/common/pages/BasePageElement/BasePageElement.ts +++ b/src/common/pages/BasePageElement/BasePageElement.ts @@ -4,19 +4,23 @@ import { BaseElement } from 'common/'; import { isTrue } from 'core/utils'; class BasePageElement extends BaseElement { - public pageTitle: string = ''; + public _pageTitle: string = ''; @attr hidetitle: string; @attr customtitle: string; private _data: any; constructor(options: OptionType) { super(); if (options?.title) { - this.pageTitle = options?.title; + this._pageTitle = options?.title; } this.connectedCallback = this.connectedCallback.bind(this); this.disconnectedCallback = this.disconnectedCallback.bind(this); } + get pageTitle() { + return this._pageTitle; + } + public renderTitle = () => { if (!isTrue(this.hidetitle)) { return html`
${this.customtitle ? this.customtitle : this.pageTitle}
`; diff --git a/src/components/app-dropdown/AppDropdownElement.ts b/src/components/app-dropdown/AppDropdownElement.ts index 8b62bc9..fe79955 100644 --- a/src/components/app-dropdown/AppDropdownElement.ts +++ b/src/components/app-dropdown/AppDropdownElement.ts @@ -33,6 +33,7 @@ class AppDropdownElement extends BaseComponentElement { page: number = 1; rpp: number = 30; validator: Validator; + itemValue: any = null; constructor() { super(); @@ -119,7 +120,10 @@ class AppDropdownElement extends BaseComponentElement { }; get selectedItem() { - const { value, valuekey, items } = this; + const { value, valuekey, items, itemValue } = this; + if (itemValue) { + return itemValue; + } const item = items?.find((item) => { return value == item[valuekey]; }); @@ -173,6 +177,7 @@ class AppDropdownElement extends BaseComponentElement { itemSelected = (e) => { const value = (e.target as HTMLSpanElement).getAttribute('data-value'); + this.itemValue = null; this.setValue(value); this.setOpen(false); this.appForm?.inputChange(e); @@ -183,6 +188,11 @@ class AppDropdownElement extends BaseComponentElement { this.update(); }; + setItemValue = (itemValue) => { + this.itemValue = itemValue; + this.update(); + } + render = () => { const { label, error, errorMessage, isOpen, searchPhrase, items, selectedItem, displaykey, valuekey } = this; diff --git a/src/components/app-form/AppFormElement.ts b/src/components/app-form/AppFormElement.ts index ed946f3..af7d956 100644 --- a/src/components/app-form/AppFormElement.ts +++ b/src/components/app-form/AppFormElement.ts @@ -77,13 +77,27 @@ class AppFormElement extends BaseComponentElement { formObject[input.name] = input._value; }); this.appDropdown?.forEach((input: AppDropdownElement) => { - if (input.required && input.value) { - formObject[input.name] = input._value; - } + formObject[input.name] = input._value; }); return formObject; } + set = (data): any => { + for (let i = 0; i < this.inputField.length; i++) { + const input = this.inputField[i]; + if(data?.[input.name]) { + input._value = data[input.name] + this.update() + } + } + this.appDropdown?.forEach((input: AppDropdownElement) => { + if(data?.[input.name]) { + input.setValue(data[input.name]) + this.update() + } + }); + } + getInput = (name: string): InputFieldElement | AppDropdownElement => { let formObject; this.inputField.forEach((input: InputFieldElement) => { diff --git a/src/components/app-link/AppLinkElement.ts b/src/components/app-link/AppLinkElement.ts index ef529df..391ea54 100644 --- a/src/components/app-link/AppLinkElement.ts +++ b/src/components/app-link/AppLinkElement.ts @@ -14,6 +14,7 @@ class AppLinkElement extends BaseComponentElement { @target main: Element; constructor() { super(); + this.attributeChangedCallback = this.attributeChangedCallback.bind(this); } elementConnected = (): void => { @@ -34,6 +35,12 @@ class AppLinkElement extends BaseComponentElement { } }; + attributeChangedCallback(changed) { + if(this.initialized && changed == 'data-title') { + this.update(); + } + } + goTo = (e: Event): void => { e.preventDefault(); if (!isTrue(this.goBack) && this.to) { @@ -46,7 +53,7 @@ class AppLinkElement extends BaseComponentElement { get disabled(): boolean { if (isTrue(this.goBack)) { - return this.routerService.emptyState; + return this.routerService?.emptyState; } return false; } diff --git a/src/components/app-menu/AppMenuElement.ts b/src/components/app-menu/AppMenuElement.ts index f9f05fb..88ba2b4 100644 --- a/src/components/app-menu/AppMenuElement.ts +++ b/src/components/app-menu/AppMenuElement.ts @@ -102,10 +102,10 @@ class AppMenuElement extends BaseComponentElement { const regularMenu = (path: string, title: string, action?: string, className?: string): TemplateResult => { if (action) { return html` - ${title} + `; } - return html`${title}`; + return html``; }; const menuButton = (title: string, action?: string): TemplateResult => { return html`