Hi,

first of all. Thanks for your help. This version seems much easier and
clearer to me. But still I do not now where to validate the input of the
field. Should I use the wicket validators? I'm not so familiar with that.
Would be kind, if you could give me one or two more hints! The models
returns valid on startup. So the textfield is green. :-( How do I change the
value returned by the isValid() method? Could you give me a hint, how to
check for "Cliff" e.g.?

If I add this line to my code it works fine.
target.appendJavaScript("document.getElementById('" + uname.getMarkupId() +
"').focus();");


But I'm still trying to use your code as it seems to me cleaner.
final TextField usernameField = (TextField) new TextField("username", new
PropertyModel(this, "username"));
       usernameField.add(new AttributeModifier("class", true, new Model() {


               public Object getObject(Component c) {
                   return usernameField.isValid() ? "valid" : "invalid";
               }
       }));

       usernameField.add(new
AjaxFormComponentUpdatingBehavior("onkeypress") {

           public void onUpdate(AjaxRequestTarget target) {
               if(!usernameField.isValid()) {
                   target.appendJavascript("document.getElementById('"
+usernameField.getMarkupId() + "').focus();");
               }
               target.addComponent(usernameField);
           }
       });


Thanks once again in advance!
Cliff




2007/1/15, Erik van Oosten <[EMAIL PROTECTED]>:

Hi Cliff,

If I read your requirements correctly you should use "onkeypress"
instead of "onblur". But I guess you already guessed that.

Regards,
    Erik.

Martijn Dashorst wrote:
> You make it very complicated :-)
>
> final TextField uname = new TextField("username", ...).add(new
> AttributeModifier("class", true, new Model() { public void
> getObject(Component c) { return uname.isValid() ? "valid" : "invalid";
> } });
>
> uname.add(new AjaxFormComponentUpdateBehavior("onblur") {
>     public void onUpdate(AjaxRequestTarget target) {
>         if(!uname.isValid()) {
> target.appendJavaScript("document.getElementById('" +
> uname.getMarkupId() + "').focus();"); }
>         target.addComponent(uname);
>     }
> });
>
> Should do the trick. Note that this is from the top of my head, so
> things might not compile completely.
>
> Martijn
>

--
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to