[英]How to set hidden window property before the component is loaded?
在我的应用程序中,我使用两个文本字段(电子邮件和密码)登录 window,并提交将这些值提交到服务器的按钮:
doLogin: function() {
var me = this,
form = me.lookupReference('form');
me.getView().mask('Authenticating... Please wait...');
form.submit({
clientValidation: true,
url: 'login.php',
scope: me,
success: 'onLoginSuccess',
failure: 'onLoginFailure'
});
},
我想在登录 window 中有一个选项“在此设备上记住我”,因此用户不需要每次都输入凭据。 我的想法是使用 cookies 来存储 email 和密码的值。 所以,我在登录表单中添加了一个复选框,成功登录后,如果选中了复选框,我将 email 保存在 cookie 中:
Ext.util.Cookies.set('MyApplication', user_email);
我对密码也是如此。 那些 cookies 可以在注销时清除。 在应用程序的最开始,我可以阅读那些 cookies
Ext.util.Cookies.get('MyApplication');
这可以在一开始就完成,或者例如在登录 window 的“beforerenderer”事件中完成。
但是现在如果用户选择了该选项,我应该跳过登录 window 出现的部分。 实际上,我根本不想跳过那个 window - 我只想隐藏它并保持它的动作。
那么,是否可以在某个地方添加类似
if (Ext.util.Cookies.get('MyApplication')){
// 1. hide the login window so it won't appear at all
// 2. Set value of email and password textfields to stored values
// 3. Submit such hidden form to the server
}
您可以在 beforerender 事件中设置 hidden 并提交表单,在这种情况下用户将看不到它(它将以隐藏模式呈现):
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create('Ext.form.Panel', {
title: 'Simple Form',
bodyPadding: 5,
width: 350,
// The form will submit an AJAX request to this URL when submitted
url: 'save-form.php',
// Fields will be arranged vertically, stretched to full width
layout: 'anchor',
defaults: {
anchor: '100%'
},
// The fields
defaultType: 'textfield',
items: [{
fieldLabel: 'Email',
name: 'email',
value: Ext.util.Cookies.get('email'),
allowBlank: false
}, {
fieldLabel: 'password',
name: 'password',
allowBlank: false,
inputType: 'password',
value: Ext.util.Cookies.get('password')
}],
// Reset and Submit buttons
buttons: [{
text: 'Reset',
handler: function () {
this.up('form').getForm().reset();
}
}, {
text: 'Submit',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function () {
var form = this.up('form').getForm();
if (form.isValid()) {
form.submit({
success: function (form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function (form, action) {
Ext.Msg.alert('Failed', action.result.msg);
}
});
}
}
}],
listeners: {
beforerender: function(loginWindow) {
if(Ext.util.Cookies.get('email') && Ext.util.Cookies.get('password')) {
console.log('Hidden');
loginWindow.setHidden(true);
loginWindow.getForm().submit();
}
}
},
renderTo: Ext.getBody()
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.