views:

1216

answers:

1

I am using the JQuery Validation plug-in and Ajax for my page. Validation works fine when I leave every thing blank. It also works fine if I enter fields besides the SKU field (the one which AJAX is being used for). I get the problem when I enter something into the SKU input but not the other inputs. When I do the this I get an error: "Error: ‘$.validator.methods[…]’ is null or not an object” and then it submits the form to the server :-P

I have looked all over for help with this situation but the most I've found is this: http://forums.asp.net/t/1070825.aspx

Any help would be appreciated!

<asp:Content ID="Content3" ContentPlaceHolderID="CustomScriptContent" runat="server">
<script type="text/javascript" src="/Scripts/jquery.rte.js"></script>
<script type="text/javascript" src="/Scripts/jquery.rte.tb.js"></script>
<script type="text/javascript">        
    $.validator.addMethod("packageSKU", function(value) {
        $.getJSON("/JSONHelper/IsPackageSKUAvailable", "packageSKU=" + value, function(data) {
            return data;
        });
    }, 'Please enter a different SKU');

    $(document).ready(function() {
        $("#LongDescription").rte({
            height: 450,
            width: 960,
            controls_rte: rte_toolbar,
            controls_html: html_toolbar
        });
        $("#packageForm").validate({           
        rules: {
                UploadedImage: { accept: "jpg|gif|png" },
                SKU: {
                    remote: {
                        url: "/JSONHelper/IsPackageSKUAvailable",
                        type: "get",
                        data: {
                            packageSKU: function() {
                                return $("#SKU").val();
                            }
                        }
                    },
                    required: true,
                    minLength: 1,
                    maxLength: 30
                }
            },
            messages: {
                SKU: {
                    remote: "This SKU is already taken"
                }
            }
        });
    });
+1  A: 

Your method should return true or false. But your method isn't returning anything

function(value) {
        $.getJSON("/JSONHelper/IsPackageSKUAvailable", "packageSKU=" + value, function(data) {
            return data;
        });

The callback of your ajax request returns 'data' but this goes nowhere.

Daniel Moura