Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20001 > unrolled thread

How to handle events tab and blur in the way that I want

Started by"Tony" <tony.johansson@inport.com>
First post2013-05-28 08:59 +0200
Last post2013-05-28 08:59 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.javascript


Contents

  How to handle events tab and blur in the way that I want "Tony" <tony.johansson@inport.com> - 2013-05-28 08:59 +0200

#20001 — How to handle events tab and blur in the way that I want

From"Tony" <tony.johansson@inport.com>
Date2013-05-28 08:59 +0200
SubjectHow to handle events tab and blur in the way that I want
Message-ID<ko1kd9$tr9$1@dont-email.me>
I have several text fieldID and corresponding readonly fields that describe 
the fieldID.
Just to explain what I mean here is an example there is a field called 
vesselID  and a read only field  called vesselName.
vesselID is a numeric number for example 100 and vesselName is the 
corresponding name for this vesselID.
So vesselID could be 100 and vesselName could be Eken.

In the function Validate that is listed further down is a call to 
"check_generic" which is a asynchronous call and this can't be changed 
because of the structure of the application.

There are two requirements. Here is one of them the other is listed further 
down.
When I tab on vesselID I need to validate the input against DB and get 
vesselName and display this for the entered vesselID. If there exist no 
vesselName for entered vesselID I give an error by using alert and keep the 
cursor in the field vesselID. So you should not be able to tab out of the 
field when the entered data is invalid.

The handling for tab on vesselID works fine and here is the code.
First I have the event handler "Keydown_FartygInNewVoyageDialog" that is 
trigger when I press a key and when Tab is pressed I validate the input.
The argument I pass is
"vesselID" is the id for this control
"AFARTYG" is the table in db to validate against
"FARTNR" is the primary key in table AFARTYG,
"F_NAMN" is the name of the description in table AFARTYG. Here it's 
vesselName
$('#vesselID').val() is the actual valud that is to be validated

///Here is the event handler for keydown
function Keydown_FartygInNewVoyageDialog(e)
{
           if (e.keyCode == TABKEY)
                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);
              }
          });
      }

Now to my problem.
The second requirement is that when you click the cursor in another field by 
using the Blur event you need to validate and get the description for 
entered vesselID.
So if I associate an event handler like this
$("#vesselID").blur(BlurOnFartyg);
and the event handler like this
function BlurOnFartyg()
{
         Validate(1, "vesselID", "AFARTYG", "FARTNR", "F_NAMN", 
$('#vesselID').val());
}

I get two calls to Validate  when I tab first the keydown event and then the 
blur event.
There is no problem when I click in another field because now only the blur 
event is fired.

The problem is the tab which fires both the keydown event and the Blur 
event.
Is it really possible to solve my problem and still keep the requirements.

//Tony

[toc] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web