JqGrid only allows numbers when editing a cell

I want my user not to enter letters in a number field. I saw that there is an option: editrules:{number:true} , but this option will allow the user to click any key that the user wants, and only after saving the line will it warn about illegal input. This is not a good option for me. I want to prevent the entry of keys that are not numbers from the very beginning (for example, in normal input I can use jQuery .numeric() ).

How can I do that?

+4
source share
3 answers

I do not use jQuery.numeric , but I suppose you should use the dataInit editoptions property for the corresponding grid column:

 editoptions: { dataInit: function (elem) { $(elem).numeric(/*some optional parameters*/); } } 

or in case of any problems in the form

 editoptions: { dataInit: function (elem) { setTimeout(function(){ $(elem).numeric(); }, 100); } } 

I hope this works.

+3
source
  {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");} }) } }}, 
+4
source

{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; } }); } } }, 
+1
source

Source: https://habr.com/ru/post/1340174/


All Articles