javascript - How to correctly change value of input form to be noticed by "change" event? -
i'm trying create keyboard input symbols in dynamically created fields. i'm using on() function handle blur , change events of input form. i'd input special chars on caret position. possible make without using global variables? change noticed if add letters keyboard , loose focus or press enter, or if type (letter , special character) || (special character , special character) without loosing blur or pressing enter.
// checking click targets var clicky; $(document).mousedown(function(e) { clicky = $(e.target); }); // handling dbclick , enter press $(document).on("dblclick", "input#word", function (){ $(this).parent().parent().css('background-color', setoneditcolor); $(this).prop("readonly", false); $(this).keypress(function(e) { if(e.which == 13) { $(this).focusout(); } }); }); // handling blur on input form $(document).on("blur", "input#word", function (e){ lastfocus = $(this); // checking if keyboardletter element clicked, // if yes want keep focus on current input if(clicky.attr('class') == 'keyboardletter'){ return false; } $(this).prop("readonly", true); $(this).parent().parent().css('background-color', setdefaultcolor); // $(this).trigger("change"); }); // onchange triggered on blur $(document).on("change", "input#word", function (){ savechanges($(this).closest('tr').attr('id'), $(this).val(), 1); }); //clicking on special characters $(document).on("click", ".keyboardletter", function (){ pos = $(lastfocus).caret(); //getting caret position of focused input lastfocus.val(lastfocus.val().insertat(pos, $(this).text().trim())); $(lastfocus).caret(pos+1); });
call .change()
after setting value:
lastfocus.val(lastfocus.val().insertat(pos, $(this).text().trim())); $(lastfocus).change(); //this line
Comments
Post a Comment