How can I accomplish this
I have JQuery-UI dialog and in this dialog I have several element of type=text.
I want to accomplish the following.
Here is what you get back from db when you want to validate data.
When you validate data for example you enter 10 in shipNumner field you get back from db if this ship nr exist and the ship name corresponding to this ship nr 10 for example Eken.
1. When I tab out of a field for example shipNr the field data is validated agains db and if the db report invalid data the focus should be set to the same field that has invalid data. So you should not be able to tab out of a field that has invalid data. If the entered data is valid you display the ship name in the description field.
2. If you focus to another field the field should be validated in the same way as point 1 but in addition the focus should not be set back to the field that has invalid data. The reason for this is just to prevent that you get stuck in a field that has invalid data.
4.One of the problems to accomplish this is that the validation againd db is done asynchronously.
5.There are three event that is important here and they are: keydown, blur and focus.
The problem starts when I use tab because this trigger the two events Keydown and Blur
if I just position the cursor in another field it works fine.
I have tried with this simple code
function Keydown_FartygInNewVoyageDialog(e)
{
if (e.keyCode == 9) //TAB
{
Validate("vesselID", "AFARTYG", "FARTNR", "F_NAMN", $('#vesselID').val());
}
}
$("#vesselID").blur(function (event)
{
Validate("vesselID", "AFARTYG", "FARTNR", "F_NAMN", $('#vesselID').val());
});
function Validate(fieldID, ipTable, ipKey, ipDesc, ipKeyValue)
{
check_generic(ipTable, ipKey, ipDesc, ipKeyValue, function (data, textStatus, jqXHR)
{
IsOkMessageShort(data.dsError);
if (data.opExist == "False")
{
alert("The Field " + fieldID + " is invalid");
setTimeout(function () { $("#" + fieldID).focus(); }, 10);
$("#" + fieldID).focus();
$("#" + fieldID + "_desc").val("");
}
else
{
//Display description field
$("#" + fieldID + "_desc").val(data.opDesc);
}
});
}
5. Is it anyone that have some example how I can accomplish this.
//Tony