emptyText被提交到表单中。

8

我正在使用 Ext Js 3.4。在使用 myform.getForm.getValues() 时遇到了一个问题。

emptytext 也会被发送到请求中。

以下是代码片段:

myForm = new Ext.FormPanel({
    id: 'myForm ',
    items: [
            {
                region:'center', 
                border:false,       
                items:[center_one]
            },{ 
                region:'west', 
                border:false, 
                items :[west_one]    
            },{ 
                region:'east', 
                border:false, 
                                items :[east_one]
            },{
                region:'south', 
                layout:'table',  
                iborder:false,
                items: [south_one]
            }
        ]
});





var west_one= new Ext.form.FieldSet({
        width: 282,
        height:250,
        layout: 'table',
                items: [{
            id: 'form1',
            layout: 'form', 
            items: [field1]
        },{
            id: 'form2',
            layout: 'form',
            items: [field2]
        }]
});



var field1 = new Ext.form.ComboBox({
        fieldLabel: 'Field',
        width: 150,
        name: 'field1',
        cls: 'fields field1',
        id: 'field1',
        store: field1Store,
        displayField: 'name',
        valueField: 'name',
        mode: 'local',
        emptyText: 'Select Field1', // This value gets submiited when no value is selected
        selectOnFocus: true,
        triggerAction: 'all',
        forceSelection : true,
        editable:true,
        typeAhead:true,
    });

这是我如何提交:

Ext.Ajax.request({
                url: 'forms.do?submit',
                method: 'POST',
                params: myForm.getForm().getValues(),                                               
                success: function(response, option){

                },
                failure: function(){

                }
            });

同样适用于Ext 4。 - Raza Ahmed
2个回答

19

您需要在submitform xtype中添加此配置:

submitEmptyText: false

默认情况下,submitEmptyText属性被设置为true。 可在在线文档中进行查看。

编辑:尝试使用以下代码而不是Ext.ajax:

var myForm = Ext.getCmp('myForm').getForm();
myForm.submit({
                                        url : 'forms.do?submit',
                                        method : 'POST',
                                        fileUpload : true,
                                        submitEmptyText : false,
                                        // waitMsg : 'Saving data',
                                        success : function(form, action) {}
});

谢谢您的回答。您能告诉我在我的代码中应该在哪里添加这个吗? - hop
在 ExtJS 5.0.1 中运行得非常好。 - Duncan
1
这个功能在ExtJS 3.4中不起作用,正如OP所要求的那样。这个功能是在ExtJS 4.0中添加的。 - Wédney Yuri

1
如果您只想获取没有 emptytext 的值(例如通过 Ext.Ajax 提交它们),请使用 myForm.getForm().getFieldValues()

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接