Form field for IP address v4 with Extjs

坚强是说给别人听的谎言 提交于 2019-12-12 10:24:02

问题


I create a form panel with Extjs 3 and i wanna create a field to put an IP address v4 like I have 4 squares to put 4 numbers. Thanks for your help


回答1:


I have used Robert B. Williams version for IP field. You can change it to fit V4 IPs with just a few twinks.

here is the code:

/**
* @class Ext.ux.form.TimeField
* @extends Ext.ux.form.FieldPanel
* This class creates a time field using spinners.
* @license: BSD
* @author: Robert B. Williams (extjs id: vtswingkid)
* @constructor
* Creates a new FieldPanel
* @param {Object} config Configuration options
*/
Ext.namespace("Ext.ux.form");
Ext.ux.form.IpField = Ext.extend(Ext.ux.form.FieldPanel, {
border: false,
baseCls: null,
layout: 'table',
token: '.',
value: '192.168.0.1',
layoutConfig: {
    columns: 7
},
width: 180,
// private
defaults:{
    maskRe: /[0-9]/,
    maxLength: 3,
    listeners: {
        'focus': function(f){
            f.selectText();
        }
    }
},
initComponent: function()
{
    this.items = [{
        xtype:'numberfield',
        width:40,
        name: this.name + '0'
    }, {
        html: '.',
        baseCls: null,
        bodyStyle: 'font-weight: bold; font-size-adjust: .9',
        border: false
    }, {
        xtype:'numberfield',
        width:40,
        name: this.name + '1'
    }, {
        html: '.',
        baseCls: null,
        bodyStyle: 'font-weight: bold; font-size-adjust: .9',
        border: false
    }, {
        xtype:'numberfield',
        width:40,
        name: this.name + '2'
    }, {
        html: '.',
        baseCls: null,
        bodyStyle: 'font-weight: bold; font-size-adjust: .9',
        border: false
    }, {
        xtype:'numberfield',
        width:40,
        name: this.name + '3'
    }]
    Ext.ux.form.IpField.superclass.initComponent.call(this);
}
});
Ext.reg('uxipfield', Ext.ux.form.IpField);


来源:https://stackoverflow.com/questions/8124043/form-field-for-ip-address-v4-with-extjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!