jqGrid allows only numbers when editing cell
I want to prevent my user from typing letters inside a numeric field.
I saw that there is an option of: editrules:{number:true}
, but this option will let the user click any key the user wants and only when row saved it will alert for illegal input. This is not good option for me. I want to prevent from the 开发者_Go百科start the typing of keys that are not numbers (for example in a regular input I can use jQuery's .numeric()
).
How can this be done?
{name:'actualNo',index:'actualNo',editable:true, edittype:"text", width:150,editoptions:{
size: 15, maxlengh: 10,
dataInit: function(element) {
$(element).keyup(function(){
var val1 = element.value;
var num = new Number(val1);
if(isNaN(num))
{alert("Please enter a valid number");}
})
}
}},
I don't use jQuery.numeric plugin myself, but I suppose you should use dataInit
property of editoptions for the corresponding grid column:
editoptions: { dataInit: function (elem) {
$(elem).numeric(/*some optional parameters*/);
}
}
or in case of some trouble in the form
editoptions: { dataInit: function (elem) {
setTimeout(function(){
$(elem).numeric();
}, 100);
}
}
I hope it will work.
{name:'rate',index:'rate', align:"left", width:'150',editable:true,
edittype:"text", editoptions:{
size: 25, maxlengh: 30,
dataInit: function(element) {
$(element).keypress(function(e){
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
}
}
},
精彩评论