views:

76

answers:

1

Hi guys,

I'm trying to add the jQuery Validation plugin to some websites and I'm running into a bit of an issue in that the fields that it's supposed to validate have a prefix on the name property, such as "Customer.FirstName".

Since you have to pass a JSON object to the validate function for the rules, it doesn't work because it never finds the elements.

Is there a way to do per field basis, or can I still pass in a variant of the JSON object that specifies the field id as a string, such as "#Customer\.FirstName"?

Thanks in advance!

EDIT:

Per Greg's suggestions, I got it to work. So for anyone who has issues like these, you have to do it like this:

$("form").validate({
    rules: {
        "Prefix.FieldName": "validationKeyword"
    }
});

DO NOT add the "#" to the selector, and DO NOT add the "\\" escape chars to the selector. So, "#Prefix\\.FieldName" will not match anything, so just leave those chars out.

A: 

JSON supports keys with "." in them - just quote them:

var obj = {"#Customer.FirstName": "value"};

In fact to be proper JSON they should always be double-quoted.

Edit: if this is a selector then you can escape the . like this: "#Customer\\.FirstName"

Edit2: The docs say the key needs to be a name so I it should either be "Customer.Firstname" or "Customer\.Firstname" depending on how well-coded the plugin is. You'll need <input name="Customer.Firstname" ...>.

Greg
Well, I'm doing that, I think? This is what I have: $("#form_holder").find("form").validate({ rules: { "#Lead\\.FirstName": { required: true } } });
Alex