jquery - Unfocus element without blur event being triggered or prevent focus all together -


i have couple of input elements behaving drop down elements in similar manner jquery date event ui works. needs stay way because of nature of application. i've set elements non-editable. allow app build pseudo dropdown menu under list of options while preventing user manipulating directly. once 1 clicked, jquery plugin assigns value input.

the issue there validation checker triggered onblur looks validator prematurely validating, of course it's working fine. hate rewrite validator plugin.

is there way prevent focus or blur event happening in particular click event?

here's js fiddle challenge

http://jsfiddle.net/powerphillg5/yhgkq/

and here's code that's there because have have code on here when providing link #law-abidingcitizen:

<input type="text" id="my_input" value="click me." /> <script> $('#my_input').blur(function(){     alert("prevent me without removing blur() , function caused me!"); });  $("#my_input").click(function(){     $(this).after("<ul>\                   <li data-value='value1' class='click_me'>now, click me,</li>\                   <li data-value='value1' class='click_me'>or me!</li>\                    </ul>");      $(".click_me").click(function(){         $("#my_input").val($(this).data("value"));         $(this).parent().remove();         $("#my_input").after("<img src='http://harrisongreetingcards.net/images/1316_thank_you_for_your_time_note_card.png' />");     })  });  </script> 

i think want unbind blur handler event, add after you've added handler:

// add after handlers want prevent added $('#my_input').unbind('blur');    

alternatively, depending things added if can't unbind handler -- because it's not been added yet -- can add own handler prevent other later added handlers going off:

// add before handlers want prevent added $("#my_input").blur(function(event) {    event.stopimmediatepropagation(); }); 

note, might have impact of overall functionality because you've prevented events happening (and might relying on them). may want rebind functionality @ point , fake event, or call specific functions.

edit: after reading question again. blur event happening before click event, can't switch off inside click event. if want blur event happen in other circumstances (when tab out of box example) you'll need cleverer. in case want write own blur handler decides do, or alternatively might need add other handlers deliberately force blur event -- perhaps when different field gets focus.

i don't know application it's difficult know need, should working.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -