ExtJS: Convert html form to ExtJS

后端 未结 2 1439
囚心锁ツ
囚心锁ツ 2021-02-06 10:33

I want to be able to convert a html form to an ExtJs form. I have read that you have to do something with applyTo but wasn\'t really sure about what to do.

I hope someon

相关标签:
2条回答
  • 2021-02-06 10:57

    If you want to convert every element in a form to an ExtJS element, someone on the Sencha forums has posted a solution (which I will cross-post here):

    function convertForm(formId) {
        var frm = new Ext.form.BasicForm(formId);
        //frm.render();
    
        var fields = frm.getValues()
    
        for (key in fields) {
    
            var elem = Ext.get(key);
            if (elem && elem.hasClass('combo-box')) {
                var cb = new Ext.form.ComboBox({
                    transform: elem.dom.name,
                    typeAhead: true,
                    triggerAction: 'all',
                    width: elem.getWidth(),
                    forceSelection: true
                });
            }
            else 
                if (elem && elem.hasClass('date-picker')) {
                    var df = new Ext.form.DateField({
                        format: 'm/d/Y'
                    });
                    df.applyTo(elem.dom.name);
                }
    
            if (elem && elem.hasClass('resizeable')) {
                var dwrapped = new Ext.Resizable(elem, {
                    wrap: true,
                    pinned: true,
                    width: 400,
                    height: 150,
                    minWidth: 200,
                    minHeight: 50,
                    dynamic: true
                });
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-06 11:19

    Additionally, who is interested, buttons can be converted too:

     var objArray = Ext.DomQuery.select("input[type=button]");      
     Ext.each(objArray, function(obj) {      
         var btn = new Ext.Button({      
             text : obj.value,      
             applyTo : obj,      
             handler : obj.onclick,      
             type : obj.type      
         });      
         btn.getEl().replace(Ext.get(obj));      
     });   
    

    Information was found here (not in English, sorry).

    0 讨论(0)
提交回复
热议问题