jquery - MVC ReadOnly textbox not working as expected with backspace and spacebar Keys -
in application, have mvc form 40 -50 different controls (textbox, dropdown , jquery date pickers). need set few textbox fields read-only in edit mode , based on user authorization, if having read privilege form, need set textbox fields readonly.
i using readonly property on disabled because, user should allowed use keyboard copy content of non-editable fields.
but coming across few issues when setting fields readonly. when ever user clicks on backspace in read field, browser functionality getting triggered , if clicks on space bar form location moving bottom of page.
i cannot add keydown event bypass these backspace , spacebar keys 30-40 different textboxes in read privilege.
can please me resolve same?
thanks in advance help.
you should way, preventing backspace or space @ focused element has readonly:
$(document).on('keydown', function(e) { if(e.keycode === 8 || e.keycode === 32 && $(':focus').attr('readonly')) { alert('prevent backspace or space!'); e.preventdefault(); } else { alert('i can backspace!'); } }); working example here: http://jsfiddle.net/fals/0qwrj1tc/
Comments
Post a Comment