I've followed the steps in this article to create a basic custom editor but I'm getting a 404 error when trying to enter Forms Edit mode from
/EPiServer/CMS/1.0.456/ClientResources/dtk/app/editors/EmailTextbox.js
The document linked article states that EPiServer automatically adds a mapping from /ClinetResources/Scripts to the app
namespace. I took a punt and added a module.config to the root of my site, like so:
<?xml version="1.0" encoding="utf-8"?>
<module>
<assemblies>
<!-- This adds the Alloy template assembly to the "default module" -->
<add assembly="PropertyTest" />
</assemblies>
<dojoModules>
<!-- Add a mapping from alloy to ~/ClientResources/Scripts to the dojo loader configuration -->
<add name="app" path="Scripts" />
</dojoModules>
</module>
This fixed the 404 but now I get a type error in the console when I try to enter forms mode
TypeError {} dojo.js:15
(anonymous function) dojo.js:15
dojo.Deferred.reject.errback dojo.js:15
_174 dojo.js:15
dojo.Deferred._171.then.then dojo.js:15
dojo.Deferred.when.dojo.when dojo.js:15
dojo.declare._createInternal widgets.js:2
(anonymous function) widgets.js:2
_388 dojo.js:15
map dojo.js:15
dojo.declare._createWidgets widgets.js:2
(anonymous function) widgets.js:2
_388 dojo.js:15
_c6 dojo.js:15
_36 dojo.js:15
_7a dojo.js:15
_ee dojo.js:15
req.injectUrl._109 dojo.js:15
Why is this erroring?
The source of my JS file is as per the linked article but I've included below for completeness.
define([
// Inherited mixins
"dojo",
"dojo/_base/declare",
"dijit/_Widget",
"dijit/_TemplatedMixin"
], function (
dojo,
declare,
_Widget,
_TemplatedMixin) {
declare("app.editors.EmailTextbox", [_Widget, _TemplatedMixin], {
// templateString: [protected] String
// A string that represents the default widget template.
templateString: '<div> \
<input type="email" data-dojo-attach-point="email" data-dojo-attach-event="onchange:_onChange" /> \
</div>',
postCreate: function () {
// summary:
// Set the value to the textbox after the DOM fragment is created.
// tags:
// protected
this.set('value', this.value);
if (this.intermediateChanges) {
this.connect(this.email, 'onkeydown', this._onIntermediateChange);
this.connect(this.email, 'onkeyup', this._onIntermediateChange);
}
},
focus: function () {
// summary:
// Put focus on this widget.
// tags:
// public
dijit.focus(this.email);
},
isValid: function () {
// summary:
// Indicates whether the current value is valid.
// tags:
// public
var emailRegex = '[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+';
if (!this.required) {
emailRegex = '(' + emailRegex + ')?';
}
var regex = new RegExp('^' + emailRegex + '$');
return regex.test(this.value);
},
onChange: function (value) {
// summary:
// Called when the value in the widget changes.
// tags:
// public callback
},
_onIntermediateChange: function (event) {
// summary:
// Handles the textbox key press events event and populates this to the onChange method.
// tags:
// private
if (this.intermediateChanges) {
this._set('value', event.target.value);
this.onChange(this.value);
}
},
_onChange: function (event) {
// summary:
// Handles the textbox change event and populates this to the onChange method.
// tags:
// private
this._set('value', event.target.value);
this.onChange(this.value);
},
_setValueAttr: function (value) {
// summary:
// Sets the value of the widget to "value" and updates the value displayed in the textbox.
// tags:
// private
this._set('value', value);
this.email.value = this.value || '';
}
});
});