How to restrict max value on html5 number input on manual entry

后端 未结 2 509
滥情空心
滥情空心 2021-01-28 10:46

Free jqgrid column is defined to use html5 number input type like

{ name: \"amount\", width: 62, template: \"number\",
             formatter: \"number\", format         


        
2条回答
  •  天涯浪人
    2021-01-28 11:22

    Try to use something like the following

    {
        name: "amount",
        width: 62,
        template: "number", // formatter: "number"
        formatoptions: {
            decimalSeparator: ",",
            thousandsSeparator: " ",
            decimalPlaces: 2,
            defaultValue: "0,00"
        },
        editoptions: {
            maxlength: 7,
            type: "number",
            max: "9999",
            dataEvents: [
                {
                    type: "blur",
                    fn: function (e) {
                            if (e.target.checkValidity()) {
                                $(e.target).removeClass("ui-state-error");
                            } else {
                                $(e.target).addClass("ui-state-error");
                                alert(e.target.validationMessage);
                                $(e.target).focus();
                            }
                        }
                }
            ]
        }
    
    }
    

    The above code calls checkValidity() method of . Of cause you need to include additional tests in the code like validation that e.target.checkValidity is a function (for the case of executing in old web browser) and some other. The above code just shows the main idea of validation which uses functionality of .

    See the demo http://jsfiddle.net/OlegKi/jhckz7rr/8/, which works for both inline editing and form editing.

提交回复
热议问题