javascript - Overriding SELECT behavior of Enter key -


working on html control more/less operates spreadsheet - matrix of editable data cells. when comes cells derived select i'm having issue getting correct behavior when type of cell selected edit:

if render select using default formatting (size = 0) user gets out-of-place behavior of select's enter-key processing:

  • 1st enter => activates editing on cell (shows select control)
  • 2nd enter => expands select show options
  • user makes selection using up/dn keys
  • 3rd enter => closes list. (problem: enter hidden "keydown" event handler)
  • 4th enter => required trigger event listener deactivating cell edit.

on other hand, if select rendered listbox (ie, size = 3, example) enter key behavior i'm looking (meaning, #2 , #3 on above list no longer required), because list displayed internally control (rather pop-up) blows cell/row sizing.

so, there way "hook" 3rd enter-key event above, or other relatively straight-forward way alter select's behavior when comes processing enter key?

note: not using 3rd party library (read: jquery, et. al)

edit: here event listener (attached via typical "addeventlistener(...)"

this.e_skeydown = function(control, event) {   switch(event.keycode) {     case 13:  // enter       control.blur()       break     case 27:  // esc = reset selection previous value       control.setattribute("data-cancelmodify", "true")       control.blur()       break   } } 

2nd edit: per comments/suggestions, i've added/given try:

this.e_sonchange = function(control, event) {   control.blur() } 

that event fire, fires each of different option/s. in other words, doesn't appear i'll have way determine if option user intended selection, or 1 traversed along way. demonstrate, here example jquery's site. note how text changes each up/down, regardless of enter-key:

http://api.jquery.com/change/

solved: commenters suggestions. indeed, solution (for situation anyway) add "keyup" event listener mix. can't browsers work in, functional in later versions of chrome.

per suggestions, way pick "hidden" enter-key event add "keyup" event listener; question has been edited reflect solution.

note: answer posted close question; please give credit due - jesus.tesh , rest of commenters suggestions...


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -