Re: [Wicket-user] Input Field background color change on validation
Hi Cliff, You can look on the Wiki: http://cwiki.apache.org/WICKET/forms.html The wicket-examples probably have some eh, examples. The basic thing is to call formfield#add(IValidator). Have fun, Erik. Cliff Pereira wrote: > 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.? > -- 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
Re: [Wicket-user] Input Field background color change on validation
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
Re: [Wicket-user] Input Field background color change on validation
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
Re: [Wicket-user] Input Field background color change on validation
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 On 1/14/07, Cliff Pereira <[EMAIL PROTECTED]> wrote: > Hello Mailinglist again, > > I tried to implement a simple input field where you can e.g. enter your > username. Now I want to let the background of the textfield be red while it > is not valid. And if it's finally valid it should change to green (during > the input). My problem is, that I always loose the focus on the input field > on correct input. I guess it has something to do with the addComponent > method. Here is my code so far > > final FormComponent usernameField; > usernameField = new TextField("username", new PropertyModel(this, > "username")); > usernameField.add(new AttributeModifier("class", true, new > PropertyModel(this, "usernamevalid"))); > usernameField.setOutputMarkupId(true); > > //this works aswell with AjaxFormSubmitBehavior. I do not see the > difference yet. > usernameField.add(new > AjaxFormComponentUpdatingBehavior("onkeyup"){ > > @Override > protected void onUpdate(AjaxRequestTarget target) { > System.out.println(username); > if (username.equals("Cliff")) { > usernameField.add(new AttributeModifier("class", true, > new Model("valid"))); > target.addComponent(usernameField); > }else { > if (usernamevalid.equals ("valid")) { > usernameField.add(new AttributeModifier("class", > true, new Model("invalid"))); > target.addComponent(usernameField); > } > } > } > > }); > add(usernameField); > > Is there a way not to loose the focus? > Thank in advance! > Cliff > > P.S.: usernamevalid could also be a boolean variable. But somehow I feel it > is not so nice code I produced here... > > - > 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 > > > -- Vote for Wicket at the http://www.thebeststuffintheworld.com/vote_for/wicket Wicket 1.2.4 is as easy as 1-2-4. Download Wicket now! http://wicketframework.org - 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
[Wicket-user] Input Field background color change on validation
Hello Mailinglist again, I tried to implement a simple input field where you can e.g. enter your username. Now I want to let the background of the textfield be red while it is not valid. And if it's finally valid it should change to green (during the input). My problem is, that I always loose the focus on the input field on correct input. I guess it has something to do with the addComponent method. Here is my code so far final FormComponent usernameField; usernameField = new TextField("username", new PropertyModel(this, "username")); usernameField.add(new AttributeModifier("class", true, new PropertyModel(this, "usernamevalid"))); usernameField.setOutputMarkupId(true); //this works aswell with AjaxFormSubmitBehavior. I do not see the difference yet. usernameField.add(new AjaxFormComponentUpdatingBehavior("onkeyup"){ @Override protected void onUpdate(AjaxRequestTarget target) { System.out.println(username); if (username.equals("Cliff")) { usernameField.add(new AttributeModifier("class", true, new Model("valid"))); target.addComponent(usernameField); }else { if (usernamevalid.equals("valid")) { usernameField.add(new AttributeModifier("class", true, new Model("invalid"))); target.addComponent(usernameField); } } } }); add(usernameField); Is there a way not to loose the focus? Thank in advance! Cliff P.S.: usernamevalid could also be a boolean variable. But somehow I feel it is not so nice code I produced here... - 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