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 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