【发布时间】:2013-01-15 10:58:42
【问题描述】:
我有一个表单,并且有一个 button 提交它。我希望只有在点击“注册”按钮时才能执行提交。但是当用户在任何textfield 中输入一些文本并按下“Go”(又名“Enter”)按钮时。表单提交了,我对此无能为力。
在 Android v2.3.6 上的 Samsung Galaxy S (GT i9000) 上发现此行为。但 Android 4 的 HTC 表现得如我所愿。
submitOnAction:false 没有帮助。
beforesubmit 也是。代码清单中的任何解决方案都不起作用。
我只是不希望表单以任何其他方式提交,除了按“注册”按钮!
文件/view/userRegistration/FormPanel.js
Ext.define('My.view.userRegistration.FormPanel', {
extend: 'My.view.components.FormPanel',
xtype : 'userRegistrationForm',
config: {
standardSubmit : false,
submitOnAction : false,
listeners: {
beforesubmit: function(form, values, options, eOpts){
console.log('before submit fired');
return false; // returning false doesn't help
},
'> field': {
keyup: function(fld, e){
//13 = user tapped 'return' button on keyboard
//10 = user tapped 'hide keyboard' on keyboard
if (e.browserEvent.keyCode == 13 || e.browserEvent.keyCode == 10) {
e.stopEvent();
fld.element.dom.blur();
}
}
}
},
items : [
{
xtype: 'textfield',
name : 'firstName',
required: true,
listeners: {
action: function(field, e, eOpts) {
e.stopEvent();
return false;
},
keyup: function(field, e) {
if (e.browserEvent.keyCode == 13 || e.browserEvent.keyCode == 10) {
// GO pressed on "firstName"
e.stopEvent();
field.element.dom.blur();
return false;
}
}
}
},
{
xtype: 'button',
text : 'Register',
listeners: {
tap: function(button) {
var form = button.parent;
if (form.isValid()) {
form.onSubmit();
}
}
}
}
]
}
});
文件/view/components/FormPanel.js
Ext.define('My.view.components.FormPanel', {
extend : 'Ext.form.Panel',
onSubmit: function() {
var fieldValues = this.getValues();
// Sending fieldValues via AJAX
},
isValid: function(args) {
// Validating values
}
});
【问题讨论】:
-
您可以断开注册按钮与表单字段的连接。监听按钮上的点击,然后手动提交表单(我不确定您使用的提交方法)。
标签: android cordova sencha-touch sencha-touch-2