c# - Prevent Key Event on DevExress ASP.NET MVC SpinEdit -


in form, have spin edit control this:

formlayoutsettings.items.add(i => {     i.fieldname = "fielda";     i.nestedextension().spinedit(s =>     {         s.properties.minvalue = 1;         s.properties.maxvalue = 9999999999999;         s.properties.validationsettings.errordisplaymode = errordisplaymode.imagewithtooltip;         s.properties.clientinstancename = "sefielda";         s.properties.increment = 10;         s.showmodelerrors = true;         s.width = unit.percentage(100);         s.properties.allowmousewheel = false;         s.properties.clientsideevents.keydown = "onfieldakeydown"; // event heandeler     }); }); 

and function:

function onfieldakeydown(s, e) {     if (e.htmlevent.keycode == 38 || e.htmlevent.keycode == 40) {         aspxclientutils.preventeventandbubble(e.htmlevent); // doesn't work         aspxclientutils.preventevent(e.htmlevent); // either     } } 

my aim prevent spin edit control value changing when user presses key or down keys. when debug this, if test inside onfieldakeydown works preventeventandbubble , preventevent fails miserably. also, there other way jquery ??

thanks.

afaik, there workaround prevent user incrementing/decrementing spinedit value using up/down arrow keys without using preventevent or preventeventandbubble. when there's no public method available on js side, can try restore spinedit previous value in keydown event handler this:

<script type="text/javascript"> function onfieldakeydown(s, e) {     if (e.htmlevent.keycode == 38 || e.htmlevent.keycode == 40) {         // check if aspxclientspinedit exists        if (typeof aspxclientspinedit !== "undefined") {            aspxclientspinedit.prototype.onpageorarrowkeydown = function() {                // when user tries either increment or decrement, returns last value instead                if (s.getvalue() != s.lastchangedvalue) {                    s.setvalue(s.lastchangedvalue);                }                // if spinedit's minimum & maximum values affected, set current limit                else {                    s.maxvalue = aspxclientspinedit.maxvalue;                    s.minvalue = aspxclientspinedit.minvalue;                }            }        }     } } </script> 

combine function jquery may possible, suggestions welcome.

reference: https://www.devexpress.com/support/center/question/details/q254514


Comments