3

我已按照本文中的步骤创建了一个基本的自定义编辑器,但尝试从以下位置进入表单编辑模式时出现 404 错误

/EPiServer/CMS/1.0.456/ClientResources/dtk/app/editors/EmailTextbox.js

文档链接文章指出,EPiServer 自动添加从 /ClinetResources/Scripts 到app命名空间的映射。我采取了平底船并将 module.config 添加到我网站的根目录,如下所示:

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

这修复了 404,但现在当我尝试进入表单模式时,我在控制台中收到类型错误

TypeError {} dojo.js:15
(匿名函数) 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
(匿名函数) widgets.js:2
_388 dojo.js:15
map dojo.js:15
dojo.declare._createWidgets 小部件.js:2
(匿名函数)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

为什么会出错?

我的 JS 文件的来源是根据链接的文章,但为了完整起见,我在下面包含了。

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 || '';
        }
    });
});
4

3 回答 3

0

您是否知道RegularExpression如果您想要电子邮件验证,您可以只使用该属性?

[RegularExpression(EPiServer.Framework.Validator.EmailRegexString)]  
public virtual string Email { get; set; }
于 2013-11-22T07:58:51.290 回答
0

如果您的脚本可以正确加载,那么最好部署脚本文件的调试版本。前往调试 EPiServer CMS 客户端文件以获取下载和有关如何部署它们的说明。

使用压缩和缩小版本很难找出问题所在。

于 2013-11-13T12:46:45.100 回答
0

如果在开发盒上发生这种情况,解决方案是禁用 Visual Studio 中的 Broswer Link。

在此处输入图像描述

http://www.herlitz.nu/2016/09/19/cant-load-the-episerver-edit-gui-in-development-environment/

于 2016-09-19T07:52:07.327 回答