From 3d0641f58b46cbb67ca529df5758e8e9eccc3abc Mon Sep 17 00:00:00 2001 From: tsng Date: Fri, 12 Apr 2024 17:39:34 +0700 Subject: [PATCH 1/2] QOL: Include Content Guid in UI view --- samples/ManagementSite/module.config | 6 +++ .../ClientResources/Scripts/Initializer.js | 41 +++++++++++++++++++ .../Templates/ContentDetailsWithGuid.html | 34 +++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 samples/ManagementSite/wwwroot/ClientResources/Scripts/Initializer.js create mode 100644 samples/ManagementSite/wwwroot/ClientResources/Templates/ContentDetailsWithGuid.html diff --git a/samples/ManagementSite/module.config b/samples/ManagementSite/module.config index 768ed75..287ef24 100644 --- a/samples/ManagementSite/module.config +++ b/samples/ManagementSite/module.config @@ -3,6 +3,12 @@ + + + + + + diff --git a/samples/ManagementSite/wwwroot/ClientResources/Scripts/Initializer.js b/samples/ManagementSite/wwwroot/ClientResources/Scripts/Initializer.js new file mode 100644 index 0000000..7bb29e2 --- /dev/null +++ b/samples/ManagementSite/wwwroot/ClientResources/Scripts/Initializer.js @@ -0,0 +1,41 @@ +define([ + "dojo/_base/declare", + "epi/_Module", + "epi-cms/contentediting/ContentDetails", + "epi-cms/contentediting/viewmodel/ContentDetailsViewModel", + "dojo/text!templates/ContentDetailsWithGuid.html" + ], function (declare, _Module, ContentDetails, ContentDetailsViewModel, template) { + + return declare([_Module], { + initialize: function () { + this.inherited(arguments); + + + //Implement extended functionality + + Object.assign(ContentDetails.prototype, { + templateString: template, + _setContentGuidAttr: { node: "guidNode", type: "innerHTML" }, + modelBindingMap: { + contentTypeName: ["contentTypeName"], + contentId: ["contentId"], + contentGuid: ["contentGuid"], + existingLanguages: ["existingLanguages"], + visibleToEveryOne: ["visibleTo"] + } + }) + + var original = ContentDetailsViewModel.prototype.onDataModelChange; //Store original functionality in variable + Object.assign(ContentDetailsViewModel.prototype, { + contentGuid: null, + onDataModelChange: function () { + this.set("contentGuid", this.dataModel.contentData.contentGuid); + return original.apply(this, arguments); + } + }) + + ContentDetailsViewModel.prototype.onDataModelChange.nom = "onDataModelChange"; + } + }) + }); + \ No newline at end of file diff --git a/samples/ManagementSite/wwwroot/ClientResources/Templates/ContentDetailsWithGuid.html b/samples/ManagementSite/wwwroot/ClientResources/Templates/ContentDetailsWithGuid.html new file mode 100644 index 0000000..0807a80 --- /dev/null +++ b/samples/ManagementSite/wwwroot/ClientResources/Templates/ContentDetailsWithGuid.html @@ -0,0 +1,34 @@ + + \ No newline at end of file From 9ad6371d42ec273d745cbd08f89e5189a5b42fab Mon Sep 17 00:00:00 2001 From: tsng Date: Fri, 12 Apr 2024 17:40:07 +0700 Subject: [PATCH 2/2] Fix number element not working properly with e value Fixes: AFORM-4094 --- .../src/components/elements/NumberElementBlock.tsx | 3 ++- src/@episerver/forms-react/src/hooks/useElement.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/@episerver/forms-react/src/components/elements/NumberElementBlock.tsx b/src/@episerver/forms-react/src/components/elements/NumberElementBlock.tsx index e015bdb..1500839 100644 --- a/src/@episerver/forms-react/src/components/elements/NumberElementBlock.tsx +++ b/src/@episerver/forms-react/src/components/elements/NumberElementBlock.tsx @@ -10,7 +10,7 @@ export interface NumberElementBlockProps { export const NumberElementBlock = (props: NumberElementBlockProps) => { const { element } = props; - const { elementContext, handleChange, handleBlur } = useElement(element); + const { elementContext, handleChange, handleBlur, handleKeyPress } = useElement(element); const { isVisible, validationResults, value, extraAttr, validatorClasses, elementRef } = elementContext; return useMemo(()=>( @@ -30,6 +30,7 @@ export const NumberElementBlock = (props: NumberElementBlockProps) => { autoComplete={element.properties.autoComplete} onChange={handleChange} onBlur={handleBlur} + onKeyDown={ handleKeyPress } ref={elementRef} /> diff --git a/src/@episerver/forms-react/src/hooks/useElement.ts b/src/@episerver/forms-react/src/hooks/useElement.ts index 491750c..cd8dbc7 100644 --- a/src/@episerver/forms-react/src/hooks/useElement.ts +++ b/src/@episerver/forms-react/src/hooks/useElement.ts @@ -184,6 +184,16 @@ export const useElement = (element: FormElementBase) => { dispatchFuncs.updateValidation(element.key, formValidation.validate(value)); } + const handleKeyPress = (e: any) => { + const { type } = e.target; + if (/number/.test(type)) { + if(e.keyCode === 69) + { + e.preventDefault() + } + } + } + const shouldResetForm = (resetConfirmationMessage: string) => { if (isNullOrEmpty(resetConfirmationMessage)) { return true; @@ -223,6 +233,6 @@ export const useElement = (element: FormElementBase) => { isVisible: isVisible.current, elementRef } as ElementContext, - handleChange, handleBlur, handleReset + handleChange, handleBlur, handleReset, handleKeyPress }; } \ No newline at end of file