编辑单元格时如何在 YUI 中显示字符数?

发布于 2024-09-18 18:35:56 字数 99 浏览 2 评论 0原文

在 YUI 数据表中,我想限制用户可以在其中一个单元格中键入的字符数。我知道如何使用格式化程序正确显示金额,但是有没有一种简单的方法可以更改编辑器框以显示“124/500”字符数限制?

In the YUI datatable I want to limit the number of characters a user can type into one of the cells. I know how to properly display the amount using a formatter, but is there a simple way to change the editor box to show a "124/500" character count limit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2024-09-25 18:35:56

您必须创建自定义 CellEditor 并重写 renderForm 方法如下

(function() {
    var Ylang   = YAHOO.lang,
        Ywidget = YAHOO.widget;

    YAHOO.namespace("yoshi");

    var yoshi = YAHOO.yoshi;

    yoshi.CustomInputText = function(settings) {
        yoshi.CustomInputText.superclass.constructor.call(this, settings);

        this.initializer(settings);
    }

    YAHOO.extend(yoshi.CustomInputText, Ywidget.TextboxCellEditor, {
         _LABEL_CLASS:"yoshi-label",
         min:null,
         max:null,
         initializer:function(settings) {
             this.min = (settings && settings.min) || null;
             this.max = (settings && settings.max) || null;
         },
         renderForm:function() {
             var pElement;
             if(Ylang.isValue(this.min) || Ylang.isValue(this.max)) {
                 pElement = document.createElement("p");

                 var minLabel = "";
                 if(Ylang.isValue(this.min)) {
                     minLabel = "min[" + this.min +  "]";
                 }

                 var maxLabel = "";
                 if(Ylang.isValue(this.max)) {
                     minLabel = "max[" + this.max +  "]";
                 }

                 pElement.innerHTML = minLabel + maxLabel;
                 pElement.className = this._LABEL_CLASS;

                 this.getContainerEl().appendChild(pElement);
             }

             yoshi.CustomInputText.superclass.renderForm.call(this);
         }
    })
})();

注意我定义了一个特定的_LABEL_CLASS,您可以在其中提供自定义CSS类

.yoshi-label {
    /* Set up custom CSS right here */
}

现在创建列设置时

var yoshi = YAHOO.yoshi;

editor:new yoshi.CustomInputText({min:124,max:500});

You must create a custom CellEditor and override renderForm method as follow

(function() {
    var Ylang   = YAHOO.lang,
        Ywidget = YAHOO.widget;

    YAHOO.namespace("yoshi");

    var yoshi = YAHOO.yoshi;

    yoshi.CustomInputText = function(settings) {
        yoshi.CustomInputText.superclass.constructor.call(this, settings);

        this.initializer(settings);
    }

    YAHOO.extend(yoshi.CustomInputText, Ywidget.TextboxCellEditor, {
         _LABEL_CLASS:"yoshi-label",
         min:null,
         max:null,
         initializer:function(settings) {
             this.min = (settings && settings.min) || null;
             this.max = (settings && settings.max) || null;
         },
         renderForm:function() {
             var pElement;
             if(Ylang.isValue(this.min) || Ylang.isValue(this.max)) {
                 pElement = document.createElement("p");

                 var minLabel = "";
                 if(Ylang.isValue(this.min)) {
                     minLabel = "min[" + this.min +  "]";
                 }

                 var maxLabel = "";
                 if(Ylang.isValue(this.max)) {
                     minLabel = "max[" + this.max +  "]";
                 }

                 pElement.innerHTML = minLabel + maxLabel;
                 pElement.className = this._LABEL_CLASS;

                 this.getContainerEl().appendChild(pElement);
             }

             yoshi.CustomInputText.superclass.renderForm.call(this);
         }
    })
})();

Notice i define a specific _LABEL_CLASS where you can supply a custom CSS class

.yoshi-label {
    /* Set up custom CSS right here */
}

Now when create a column settings

var yoshi = YAHOO.yoshi;

editor:new yoshi.CustomInputText({min:124,max:500});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文