Hello,

I'm trying to replicate browser autocomplete on a login form.  For
example, every time you go to the login page, I'd like the username
and password field to be prepopulated with the username/password you
used last.  Not only that, but if you clear the username and double
click the field, the list of previous usernames you've entered should
show up.  If you select one, the password field gets populated with
that.

Fortunately, with normal HTML the browser handles all of this for
you.  But I can't figure out how to get this to work on IE6/7 on an
GWT app.  In these browsers, it doesn't offer to save the usernames.
I'll provide the code I have so far (this works in FF):

public class Sandbox implements EntryPoint, ClickListener,
KeyboardListener {

    private Label label;
    private FormPanel formPanel;

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        formPanel = new FormPanel();
        final VerticalPanel basePanel = new VerticalPanel();
        formPanel.add(basePanel);

        TextBox loginTB = new TextBox();
        //without this, FF doesn't know where to place the data
        loginTB.setName("name");
        basePanel.add(loginTB);


        PasswordTextBox passTB = new PasswordTextBox();
        //without this, FF doesn't know where to place the data
        passTB.setName("password");
        basePanel.add(passTB);

        Button loginBT = new Button("Submit");
        basePanel.add(loginBT);


        RootPanel.get("slot1").add(formPanel);

        loginTB.addKeyboardListener(this);
        passTB.addKeyboardListener(this);
        loginBT.addClickListener(this);

        label = new Label();
        RootPanel.get("slot2").add(label);
    }

    public void onClick(Widget sender) {
        //Without this, FF doesn't offer to remember the data
        formPanel.submit();
        if (label.getText().equals("")) {
            SandboxService.App.getInstance().getMessage("Hello,
World!", new MyAsyncCallback(label));
        } else
            label.setText("");
    }

    public void onKeyDown(Widget sender, char keyCode, int modifiers)
{
    }

    public void onKeyPress(Widget sender, char keyCode, int modifiers)
{
    }

    public void onKeyUp(Widget sender, char keyCode, int modifiers) {
        // If enter is pressed lets forward the request to onClick
method
        if (keyCode == '\r') {
            onClick(sender);
        }
    }

    static class MyAsyncCallback implements AsyncCallback {
        public void onSuccess(Object object) {
            DOM.setInnerHTML(label.getElement(), (String) object);
        }

        public void onFailure(Throwable throwable) {
            label.setText("Failed to receive answer from server!");
        }

        Label label;

        public MyAsyncCallback(Label label) {
            this.label = label;
        }
    }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to