html5 has number input type like
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<input type="number" />
</body>
</html>
In this case non-numeric characters are disabled on entry. Native numeric-only keypad appears automatically in touch devices.
How to force free jqgrid field edit to use this type ?
jgrid column is defined as
{"label":"Quantity","name":"Valkogus",
"index":"Valkogus","align":"right",
"searchoptions":{"sopt":["eq","ne","lt","le","gt","ge"]},
"editoptions":{"maxlength":7,
"dataEvents":[{"type":"change","fn":function(e) {dataChanged(e.target)}
},
{"type":"focus","fn":function(e) {if(typeof e.target.ischanged=='undefined') {e.target.ischanged=false}}
}],"style":"text-align:right","readonly":null,"class":"jqgrid-inlineedit-element ","disabled":null},
"editable":true,"width":62,
"classes":null,"hidden":false},
jqgrid is created from remote json data. inline and form editing and search toolbar is used. This allows to enter any characters. In touch devices full keyboard appears.
How to fix this so that in edit and toolbar search this field appears with type="number"
attribute?
How to specify that input is integer only or allows decimal places? Maybe html5 validation attributes and also added to created input element for this.
Answer in How to use native date picker in both form and row editing in free jqgrid describes html5 native datepicker usage. Maybe this can used got number input also
Update
I created customer formatter using sample from
Add multiple input elements in a custom edit type field
Colmodel:
{"edittype":"custom",
"name":"Kogus",
"align":"right",
"searchoptions":{"sopt":["eq","ne","lt","le","gt","ge"]},
"editoptions":{"custom_element":function(value, options) {
return numeric_element(value, options,'58','Kogus','RidG','ArtKogus')}
,
"custom_value":combobox_value,
"maxlength":12,
"style":"text-align:right",
"readonly":null,
"disabled":null
},
"editable":true,
"width":58,
"classes":null,
"hidden":false
},
javascript
function numeric_element(value, options, width, colName, entity, andmetp) {
var elemStr, newel;
elemStr = '';
if (options.id === options.name) {
elemStr += '<input type="number" class="FormElement" size="' +
options.size + '"' + ' id="' + options.id + '"';
}
else {
elemStr += '<input type="number" ' +
' style="text-align: right; width: 100%; box-sizing: border-box;" ' +
' id="' + options.id + '" maxlength="'+ options.maxlength+'" name="'+options.name+'"';
}
elemStr += ' value="' + value + '"/>';
newel = $(elemStr);
return newel;
}
function combobox_value(elem, operation, value) {
if (operation === 'get') {
return $(elem).find("input").val();
} else if (operation === 'set') {
$('input', elem).val(value);
}
}
If inline edititing is started, number disappears in cell. After pressing inline save button, error function 'custom_value' undefined
appears.
How to fix those issues ?