ExtJS中的NumberField提示符 [英] NumberField prompt in ExtJS

查看:217
本文介绍了ExtJS中的NumberField提示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示一个MessageBox.prompt与一个数字字段而不是常规的文本字段。
我不能去创建一个新的MessageBox,所以我决定只使用验证器,但我也有麻烦。

I'm trying to show a MessageBox.prompt with a numberfield instead of a regular textfield. I couldn't go around creating a new MessageBox so I decided to just use a validator instead, but I'm having some trouble with it too.

所以任何事情都可以为我工作,无论是MessageBox的号码验证器还是带有字段而不是textfield的MessageBox。

So anything will work for me, either a number validator for a MessageBox or a MessageBox with a numberfield instead of textfield.

这是我的MessageBox ...

Here's my MessageBox...

var msgbox = Ext.Msg.prompt('Quantity', 'Enter a number',function(btn, text){} )

任何想法?

更新

我设法使验证器工作,但我宁愿有一个数字字段而不是一个文本字段,所以问题的第一部分仍然是。

I managed to get the validator working, but I would much rather have a numberfield instead of a textfield, so the first part of the question is still up.

如何在ExtJS上的MessageBox.prompt上显示一个字段而不是一个文本框。

How do I get to show a numberfield instead of a textfield on a MessageBox.prompt on ExtJS.

推荐答案

看起来他不能没有黑客。 Ext.Msg是一个单例,在initComponent中,文本字段被设置,并且它是不可配置的。 http:// docs .sencha.com / ext-js / 4-1 / source / MessageBox.html#Ext-window-MessageBox-method-initComponent

It looks like his can't be done without a "hack". Ext.Msg is a singleton and in the initComponent the text field is set up and it is not configurable. http://docs.sencha.com/ext-js/4-1/source/MessageBox.html#Ext-window-MessageBox-method-initComponent

既然是一个单身一个重写将不起作用,这不是解决问题的一个很好的解决方案。

Since it is a singleton an override will not work and it not a good solution to the problem.

Messagebox的扩展名应该可以工作,但代码必须在$ b上查看$ b每个Ext升级,因为MessageBox代码没有很多钩子。

An extension of Messagebox should work but the code will have to be looked at on every Ext upgrade since the MessageBox code does not have many hooks.

Ext.define('NumberPrompt', {
    extend: 'Ext.window.MessageBox',
    initComponent: function() {
        this.callParent();
        var index = this.promptContainer.items.indexOf(this.textField);
        this.promptContainer.remove(this.textField);
        this.textField = this._createNumberField();
        this.promptContainer.insert(index, this.textField);
    },

    _createNumberField: function() {
        //copy paste what is being done in the initComonent to create the textfield
        return new Ext.form.field.Number({
                        id: this.id + '-textfield',
                        anchor: '100%',
                        enableKeyEvents: true,
                        listeners: {
                            keydown: this.onPromptKey,
                            scope: this
                        }
        });
    }
});



var msgbox = new NumberPrompt().prompt('Quantity', 'Enter a number',function(btn, text){} )

这篇关于ExtJS中的NumberField提示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆