views:

23

answers:

0

I'm using jQuery autocomplete on a text box so the user can select a trade. I need to make this a required field. I'm also using jQuery Validation.

Here's my autocomplete cpde:

$(\"#trade\").autocomplete({
    source: " . $tradeString . ",
    maxHeight:100,
    autoFill: true,
    minLength: 3,
    close: function() { $(\"#form\").validate().element(\"#trade\"); }
}).select(function() {
    $(this).autocomplete(\"search\");
});

And here's my jQuery validation code:

$("#form").validate({   
    errorElement:   "div",
    validClass:     "input_ok",
    errorClass:     "validation_error",
    rules: {    "address[postcode]":         { required:     true},
                "general[trade]":           { required:     true},
                "address[address_line_1]":   { required:    true},
                "address[address_line_2]":   { required:    true},
                "address[address_line_3]":   { required:    true},
                "general[trade]":           { remote:       true,
                                               required:     true}

          },
     messages: {    trade:                  { remote: "Trade not found."}                               
          }
});

Can anyone help me out? I've done this before, but using a remote call to a PHP script that looked up the trade from the database. This isn't necessary on this occasion as $tradeString returns the list of trades in the format the autocomplete expects.