0

zk mvvm focus textbox after a button clicked

asked 2013-03-21 02:54:16 +0800

progamerdotcom gravatar image progamerdotcom
117 5

I have code as shows below :

<textbox value="@bind(vm.username)" type="text" width="200px" />
<textbox value="@bind(vm.password)" type="text" width="200px" />
<button label="Submit" onClick="@command('save')" />

in mvvm concept, how to setFocus to 'username textbox' after 'save button' clicked ??

thanks a lot,

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-03-22 02:46:23 +0800

samchuang gravatar image samchuang
4084 4

updated 2013-03-22 02:48:28 +0800

Hi, you can simply bind a boolean value and use @NotifyChange


<zk>
<window title="new page title" border="normal" apply="org.zkoss.bind.BindComposer" viewmodel="@id('vm') @init('test.FocusVM')">
    
    <textbox type="text" width="200px" focus="@load(vm.userNameFocus)"/>
    <button label="Focus User Name" onclick="@command('doFocusUserName')"/>

    
    <textbox width="200px" focus="@load(vm.getFocus('password'))"/>
    <button label="Focus Passowrd" onclick="@command('doFocusPassword')"/>
</window>
</zk>
 

public class FocusVM {

    String focus;
    boolean isUserNameFocus;

    public boolean getFocus(@BindingParam("target") String target) {
        return Objects.equals(focus, target);
    }

    public boolean getUserNameFocus() {
        return isUserNameFocus;
    }

    @Command
    @NotifyChange("userNameFocus")
    public void doFocusUserName() {
        isUserNameFocus = true;
    }

    @Command
    @NotifyChange("getFocus")
    public void doFocusPassword() {
        focus = "password";
    }
}
 
link publish delete flag offensive edit

Comments

You mean to say, there two ways to achieve this functionality ? Because implementation of giving focus to password and user name are different.

Senthilchettyin ( 2013-03-22 05:50:52 +0800 )edit

thanks samchuang, its works

progamerdotcom ( 2013-03-22 09:01:34 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-03-21 02:54:16 +0800

Seen: 127 times

Last updated: Mar 22 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More