I have a select box and an input box that, together, need to be validated against the database.
<select name="gameID" id="gameID">
<option value="">Select</>
<option value="1>Game1</>
<option vlaue="2>Game2</>
</select>
<input type="text" name="title" id="title">
My javascript validation plugin snippet looks like this:
title: {
required: true,
remote: function(){
return {
type:"POST",
url: "/services/my.cfc?method=checkTitleDupe",
data: "gameid="+$('#gameID').val() + "&title=" + $('[name=title]').val(),
cache: false
开发者_JS百科 }
}
},
gameTitle: {required: true}
This does a check of the title against the database and it's categorization.
If I select Game1 and I type in a title that matches the database, I get an error.
Now I go back and change the gameID to Game2 and leave the title the same.
Basically this should be valid. There is no title that is categorized as Game2. But, the validation doesn't execute. Watching my firebug console, I don't see a 2nd ajax call after I blur from Game1 AND blur from title.
Anyone have any thoughts how I can get the validation to execute again?
So the answer is this:
$("#gameID").change(function(){
$("#title").removeData("previousValue");
});
This clears the cached value of the remote call.
精彩评论