【问题标题】:Input text field auto-complete does't take the data when I submit the form提交表单时,输入文本字段自动完成不接受数据
【发布时间】:2016-12-08 16:25:11
【问题描述】:

我有一个输入数据登录:用户名和密码并提交按钮。像这样。

那里的文本字段由 Chrome 填充,但是当我使用该信息进行登录过程时,就像没有数据一样。我必须重写文本字段中的所有信息。我希望将此信息用于登录过程。 我该怎么做?

控制器类:

public class LoginController extends SelectorComposer<Component>{
    //Wire Components
    @Wire
    private Textbox user;
    @Wire
    private Textbox password;
    @Wire
    private Label message;

    private AuthenticationService serviceAuth = new AuthenticationService();

    /*
     * Method:  doLogin
     * Details: Login function with the data provided: User and password
     * 
     */
    @Listen("onClick=#loginButton")
    public void doLogin(){
        String userName = user.getValue();
        String pass = password.getValue();

        //Now we use the Authenthication service
        if(!serviceAuth.login(userName, pass)){
            message.setValue("Datos ingresados son incorrectos");
            return;
        }

        UserCredential tmpCred = serviceAuth.getUserCredential(); //check
        message.setValue("Bienvenido, "+userName);
        Executions.sendRedirect("/inquiries.zul");
    }
}

【问题讨论】:

    标签: html forms zk


    【解决方案1】:

    这可能听起来很奇怪,但您可以尝试以下方法:

    <textbox value="@bind(vm.userName) @save(vm.userName, before='submit')"/>
    <button onClick="@command('submit')"/>
    

    像这样,您将在保存之前再次持久化文本框中的数据。

    编辑:

    所以我搜索了一下,发现了一些“hack”。
    请注意,问题来自 Chrome 本身,它不执行 onChange 事件。

    所以我想出了以下内容:

    <window id="win" border="normal" title="hello" apply="be.chillworld.LoginController" xmlns:w="http://www.zkoss.org/2005/zk/client" >
         <vlayout>
            <textbox id="user"/>   
            <textbox id="password" type="password"/>
            <button label="login" id="loginButton" w:onClick="persistValuesToServer()"/>   
            <script type="text/javascript">
                function persistValuesToServer()
                {
                zAu.send(new zk.Event(zk.Widget.$('win'), 'onUser', jq('$user').val()));
                zAu.send(new zk.Event(zk.Widget.$('win'), 'onPass', jq('$password').val()));
                }
            </script>
        </vlayout>  
    </window>
    
    
    public class LoginController extends SelectorComposer<Component> {
    
        @Wire
        private Textbox user;
        @Wire
        private Textbox password;
    
        @Listen("onUser=#win")
        public void autoFillUser(Event e) {
            user.setValue(String.valueOf(e.getData()));
        }
    
        @Listen("onPass=#win")
        public void autoFillPass(Event e) {
            password.setValue(String.valueOf(e.getData()));
        }
    
        @Listen("onClick=#loginButton")
        public void doLogin() {
            System.out.println(user.getValue() + " : " + password.getValue());
        }
    }
    

    小解释:
    当我们按下按钮时,我们的 JavaScript 将首先被触发 =>,我们将向控制器发送 2 个事件(1 个用于用户名,1 个用于密码),其中包含实际文本框中的数据。
    在控制器中,我们将正确的数据放入文本字​​段中,然后处理真正的登录事件。

    这是完美的解决方案吗? 当然不是,但是当我们按下按钮时,它的工作开销很小。

    【讨论】:

    • 是的,我怎样才能用 MVC 做到这一点?
    • 能否给出一些代码,MVC中有很多不同的方式来实现登录表单。
    • 您能提供反馈吗?
    • 嗨,@chillworld。感谢您花时间回答我的问题。我会尝试你的解决方案,然后我会给你一个反馈(:
    猜你喜欢
    • 2020-01-13
    • 2014-02-05
    • 2020-02-23
    • 2011-01-01
    • 1970-01-01
    • 2017-07-27
    • 2017-08-29
    • 1970-01-01
    • 2017-05-11
    相关资源
    最近更新 更多