Custom ClientScriptWriter

26 views
Skip to first unread message

Gary Stanton

unread,
Mar 23, 2013, 10:08:23 PM3/23/13
to valida...@googlegroups.com
Hi,

I've been trying to integrate ValidateThis into a system that's using the Bootstrap front end framework.
I'd like to change the way that the client side JS is written by VT, so that the error messages fit in with Bootstrap's requirements.
I'm fairly new to OOP concepts and as such, I find it difficult to really get into the guts of VT to bend it to my will. As far as I can tell, I need to extend the jQuery ClientScriptWriter component with my own, to override the generateScriptFooter function. I'm not having any luck doing this however.
Can anyone show me an example of how I'd go about doing this?

Thanks.

Matt Quackenbush

unread,
Mar 23, 2013, 10:13:55 PM3/23/13
to valida...@googlegroups.com
Hmm, I may be misunderstanding what you're trying to do, but I don't believe you need to do anything at all with VT. Let's see if I'm even in the ball park. :-)

I _think_ you're trying to alter where the client-side validation messages get attached. If that is correct, that's done quite easily with a bit of JS. Something like the following for Bootstrap.

    $(document).ready(function(){
        $.validator.setDefaults({
            errorClass:'help-inline',
            errorElement:'span',
            errorPlacement:function( error, element ){
                error.appendTo( element.parents( '.controls' ) );
            },
            highlight:function( element, errorClass ){
                $(element).parents( '.control-group').addClass( 'error' );
            },
            unhighlight:function( element, errorClass ){
                $(element).parents( '.control-group').removeClass( 'error' );
            }
        });
    });


HTH



--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to validatethis...@googlegroups.com.
To post to this group, send email to valida...@googlegroups.com.
Visit this group at http://groups.google.com/group/validatethis?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gary Stanton

unread,
Mar 23, 2013, 10:21:26 PM3/23/13
to valida...@googlegroups.com
Hah! That works perfectly, thanks!

I hadn't considered that I could add defaults in the jQuery validate plugin... I guess I should have read the docs first - I just figured since VT was inserting inline JS, I'd need to change what it was inserting.

Thanks for the help.

Matt Quackenbush

unread,
Mar 23, 2013, 10:27:30 PM3/23/13
to valida...@googlegroups.com
Schweeeeeet!  :-)

For what it's worth, VT simply allows the jQuery validate plugin to use its defaults on things like that. The plugin (as you can see) makes it super easy to override message placement.

Anywho, glad to help!


Reply all
Reply to author
Forward
0 new messages