Question

I'm just trying to do something along those lines here with ScriptSharp:

$('#yourform').bind('change keyup', function() {
    if($(this).validate().checkForm()) {
        // do something
    }
});

(see https://stackoverflow.com/a/6072997/465509)

But I can't seem to figure out how to use the jQueryValidator object.

This is my approach so far:

namespace TestSite.Script.Validation
{
    internal class FormValidationSetup
    {
        internal FormValidationSetup()
        {
            jQuery.OnDocumentReady(delegate
            {
                jQuery.Select("#yourform").Bind("change keyup", delegate(jQueryEvent @event)
                {
                    jQueryValidator validator = (jQueryValidator) System.Script.Literal("{0}.validate()", jQuery.FromElement(@event.Target));
                    if (validator.ValidateForm())
                    {
                        // do something
                    }
                });
            });
        }
    }
}

But that throws some odd errors:

Error 3 Check that your C# source compiles and that you are not using an unsupported feature. Common things to check for include use of fully-qualified names (use a using statement to import namespaces instead) or accessing private members of a type from a static member of the same type.

(I'm using ScriptSharp 0.8)

Any help is appreciated.

-- edit --

Added namespace in the sample above, since it seems to cause the error.

Was it helpful?

Solution

Try the following:

jQuery.FromElement(e.Target).Plugin<jQueryValidationObject>().Validate();

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top