Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aform 4094 number element not working with e value #120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions samples/ManagementSite/module.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<!-- Add a mapping from alloy to ~/ClientResources/Scripts to the dojo loader configuration -->
<paths>
<add name="alloy" path="Scripts" />
<add name="templates" path="Templates" />
</paths>
</dojo>
<clientModule initializer="alloy/Initializer">
<moduleDependencies>
<add dependency="CMS" type="RunAfter" />
</moduleDependencies>
</clientModule>
</module>
Original file line number Diff line number Diff line change
@@ -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";
}
})
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<ul class="epi-form-container__section">
<ul data-dojo-type="epi/shell/layout/SimpleContainer" data-dojo-attach-point="widgetContainer"></ul>
<li class="epi-form-container__section__row">
<label>${resources.visibleto.title}</label>
<div class="epi-previewableTextBox-wrapper dijitInline">
<span data-dojo-attach-point="visibleToNode" class="epi-previewableTextBox-text dojoxEllipsis dijitInline"></span>
<div data-dojo-type="dijit/form/Button" data-dojo-attach-point="manageAccessRightsButton" data-dojo-attach-event="onClick: _onManageAccessRightsClick" class="epi-chromelessButton epi-chromelessLinkButton epi-functionLink epi-valign--top">${resources.manage}</div>
</div>
</li>
<li class="epi-form-container__section__row">
<label>${resources.existinglanguages}</label>
<span data-dojo-attach-point="languagesNode" class="epi-previewableTextBox-text dijitInline"></span>
</li>
<li class="epi-form-container__section__row">
<label>${resources.idandtypename}</label>
<div class="epi-previewableTextBox-wrapper dijitInline">
<span class="epi-previewableTextBox-text dojoxEllipsis dijitInline">
<span data-dojo-attach-point="idNode"></span>, <span data-dojo-attach-point="typeNode"></span>
</span>
</div>
</li>
<li class="epi-form-container__section__row">
<label>Guid</label>
<span data-dojo-attach-point="guidNode" class="dojoxEllipsis dijitInline"></span>
</li>
<li class="epi-form-container__section__row">
<label></label>
<div data-dojo-attach-point="dropdownButton" data-dojo-type="dijit/form/DropDownButton" class="dijit dijitReset dijitInline epi-mediumButton">
<span>${resources.toolsbutton.label}</span>
<div data-dojo-type="dijit/DropDownMenu" data-dojo-attach-point="additionalActionsMenu"></div>
</div>
</li>
</ul>

Original file line number Diff line number Diff line change
Expand Up @@ -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(()=>(
Expand All @@ -30,6 +30,7 @@ export const NumberElementBlock = (props: NumberElementBlockProps) => {
autoComplete={element.properties.autoComplete}
onChange={handleChange}
onBlur={handleBlur}
onKeyDown={ handleKeyPress }
ref={elementRef}
/>

Expand Down
12 changes: 11 additions & 1 deletion src/@episerver/forms-react/src/hooks/useElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -223,6 +233,6 @@ export const useElement = (element: FormElementBase) => {
isVisible: isVisible.current,
elementRef
} as ElementContext,
handleChange, handleBlur, handleReset
handleChange, handleBlur, handleReset, handleKeyPress
};
}
Loading