You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by BatiB80 <se...@torexretail.de> on 2007/11/09 13:47:46 UTC

Change css-class of form on validation

Hi@all,

I want to use a different css-class for my inputfields after the validation
of that field has failed. For example, if an requiredfield isn't filled, the
field should get red. 

Does anybody knows how to do this? Furthermore I do not want to have the
message "field ... is required" in my feedback panel.

Thanks 
Sebastian
-- 
View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13666379
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by BatiB80 <se...@torexretail.de>.
Great, many thanks!
-- 
View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13667331
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Fri, 09 Nov 2007, BatiB80 wrote:
> example: myfield.add(new AttributeModifier("class", getClassValue());

myfield.add(new RedIfInvalid(myfield));

public class RedIfInvalid extends AttributeModifier() {
    private final FormComponent component;

    public RedIfInvalid(FormComponent component) {
        super("class", true, new AbstractReadOnlyModel() {
	    @Override
	    public Object getObject() {
	        if (component.isValid() {
		    return "green";
		}
		return "red";
	    }
	}
	this.component = component;
    }
}

Or something like that. 

It's a bit tricky if you want to make it work on ajax (e.g.
with OnChangeAjaxBehavior, I think you have to explicitly
call validate() or something), but very cool :)

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by BatiB80 <se...@torexretail.de>.
I found something in the wiki :-)

http://cwiki.apache.org/WICKET/removing-message-bundle-requirements-for-validation.html

-- 
View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13668693
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by Al Maw <wi...@almaw.com>.
BatiB80 wrote:
> Hmmm... - sorry, but one more question on this. I added an attributemodifier
> to my component. When accessing the page the attribute is correctly
> renderred. But I want to "rerender" the component after the validation
> failed. But the validation method isn't called again.
> 
> example: myfield.add(new AttributeModifier("class", getClassValue());
> 
> The method getClassValue is only called when the page is displayed the first
> time. After validation I want to called it again, but it isn't. Does anybody
> knows why???

Well, why do you think? You're calling getClassValue() once, at 
constructor time.

Take a look at the other constructors for AttributeModifier.

Regards,

Al

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by BatiB80 <se...@torexretail.de>.
Hmmm... - sorry, but one more question on this. I added an attributemodifier
to my component. When accessing the page the attribute is correctly
renderred. But I want to "rerender" the component after the validation
failed. But the validation method isn't called again.

example: myfield.add(new AttributeModifier("class", getClassValue());

The method getClassValue is only called when the page is displayed the first
time. After validation I want to called it again, but it isn't. Does anybody
knows why???

Thanks,
Sebastian
-- 
View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13668008
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by Martijn Dashorst <ma...@gmail.com>.
1 minute of browsing the wiki gave me this:

http://cwiki.apache.org/WICKET/form-validation-messages.html

Martijn

On 11/9/07, BatiB80 <se...@torexretail.de> wrote:
>
> But in which message do I have to override it?
> I use the RequiredText- and PasswordTextField. Do I have to extend this
> classes with my own versions or where I can override the message?
> --
> View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13667225
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta4/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by BatiB80 <se...@torexretail.de>.
But in which message do I have to override it? 
I use the RequiredText- and PasswordTextField. Do I have to extend this
classes with my own versions or where I can override the message?
-- 
View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13667225
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Change css-class of form on validation

Posted by Martijn Dashorst <ma...@gmail.com>.
Then override the message with an empty string.

Add an attribute modifier that modifies the class attribute when the
form component is invalid.

Martijn

On 11/9/07, BatiB80 <se...@torexretail.de> wrote:
>
> Hi@all,
>
> I want to use a different css-class for my inputfields after the validation
> of that field has failed. For example, if an requiredfield isn't filled, the
> field should get red.
>
> Does anybody knows how to do this? Furthermore I do not want to have the
> message "field ... is required" in my feedback panel.
>
> Thanks
> Sebastian
> --
> View this message in context: http://www.nabble.com/Change-css-class-of-form-on-validation-tf4777497.html#a13666379
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta4/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org