AnsweredAssumed Answered

Why won't my code run a second time on lost focus of an element?

Question asked by csergent08 Champion on Aug 18, 2015
Latest reply on Aug 19, 2015 by csergent08

I run a block of code that runs off of lost focus. It runs fine the first time, but then I try to set focus to a textbox(which appears not to work) so I click in the textbox and tab out. The lost focus event does not work that time? Why is that?

 

Here is the related code:

 on(document.getElementById('ownerAddress'), 'focusout', checkAddress);


                 on(document.getElementById('ownerAddress'), 'focusin', getElementId);


                 function getElementId() {
                                                               
                     node = document.activeElement.id;
                    
                 }




                 function checkAddress() {
                     console.log(node);
                     var locator = new Locator("http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer");
                     //console.log(document.getElementById('ownerAddress').value);
                     //node = document.getElementById('ownerAddress');
                     node = document.getElementById(node);
                     // according to your service it takes Single Line
                     var params = {
                         "Single Line Input": node.value
                     };
                     locator.addressToLocations(params).then(function (addressCandidates) {
                         //console.log('success', addressCandidates);
                         //console.log(addressCandidates.length);


                         data = {
                             identifier: "id",
                             items: []
                         };


                         layout = [[
                        //   {'name': 'FID', 'field': 'id', 'width': '50px'},//
                           { 'name': 'Address', 'field': 'address', 'width': '200px' }
                         ]];
                         if (addressCandidates.length > 1) {
                             for (a = 0; a < addressCandidates.length; a++) {
                                 // This is the address that should go into a grid cell
                                 data.items.push(lang.mixin({ id: a + 1 }, { address: addressCandidates[a].address }));
                                 console.log(addressCandidates[a].address);




                             }
                             console.log(addressCandidates);
                             items = arrayUtils.map(addressCandidates, function (result) {
                                 console.log(result);
                                 return result;
                             });
                             console.log(items);
                         }




                         console.log("Log" + data);
                         if (window.grid) {
                             Maingds
                             dojo.destroy('grid');
                             dijit.byId('grid').destroy(true);
                             registry.remove(dom.byId('gridDiv'));
                         }
                         store = new ItemFileWriteStore({ data: data });
                         grid = new DataGrid({
                             id: 'grid',
                             store: store,
                             structure: layout,
                             autoWidth: true,
                             autoHeight: false,
                             rowSelector: '20px'
                         });


                         
                         // display grid
                         //document.getElementById("grid").style.display = "block";
                         //alert("hello " + addressCandidates.length);
                         // Show modal
                         if (addressCandidates.length >= 1) {
                             $("#myModal").modal("show");
                             $('#myModal').show(function () {
                                 $(this).trigger('isVisible');




                             });


                             //registry.byId("grid").display=block;
                             grid.on("rowclick", onRowClickHandler);
                             //console.log(addressCandidates.length);




                             //hookup the event
                             $('#myModal').bind('isVisible', isVisible);




                             var adresses = addressCandidates.map(function () {
                                 return x.address;


                             });
                             //console.log(adresses);
                         }
                         else
                         {
                             alert("This address does not appear to be a city address. Please try again.");
                             document.getElementById(node).focus();
                         }


                     }).otherwise(function (err) {
                         console.log('somethings wrong', err);
                     });




                 }




                 //declare event to run when div is visible
                 function isVisible() {
                     /*append the new grid to the div*/
                     grid.placeAt("gridDiv");
                     /*Call startup() to render the grid*/
                     grid.startup();


                 }


                 function onRowClickHandler(evt) {
                     console.log(evt);
                     var clickedAddress = evt.grid.getItem(evt.rowIndex).address;
                     console.log(clickedAddress);
                     alert(clickedAddress);
                     //  console.log(evt.explicitOriginalTarget.data);
                 }
             });

Outcomes