1

Firefox 37.0.1 on Windows 7 Pro. jqGrid 4.4.1, cell editing mode. Two editable cells act differently on submit and I can't figure out why. column1 element has maxValue passed as {{maximum_discount_value}}, and when I go over the limit it gives a pop-up with the error description mentioning max allowed value correctly. column2 element mas maxValue pointing to a function returning maxValue, and when I go over the limit it silently changes the value in the table to allowed maxValue about a second after I hit enter instead of giving me the same pop-up as I expect. What makes column2 to behave differently and how to make it to give me a pop-up? Thanks.

$("#{{ grid_id }}").jqGrid({
        '{% trans "JQGRID_COLUMN1" %}',
        '{% trans "JQGRID_COLUMN2" %}',
    colModel:[
        {name : "column1", index : "some_index1",
            width : 25,
            sortable : false,
            classes : "editable",
            editable : true,
            edittype : "custom",
            editrules : {
                number : true,
                minValue : 0,
                maxValue : {{ maximum_discount_value }}
            },
            editoptions : {
                maxlength : 5,
                size : 5,
                custom_element: function_for_element,
                custom_value: function_for_value
            }
        {name : "column2", index : "some_index2",
            width : 25,
            sortable : false,
            classes : "editable",
            editable : true,
            edittype : "custom",
            editrules : {
                number : true,
                minValue : 0,
                maxValue : function_for_maximum_discount_value
            },
            editoptions : {
                maxlength : 5,
                size : 5,
                custom_element: function_for_element,
                custom_value: function_for_value
            }
            ]

function function_for_maximum_discount_value(elem) {
    maximum_discount_value=  $(elem).attr("maximum_discount_value");
    return maximum_discount_value;
}
SwissNavy
  • 619
  • 1
  • 12
  • 28
  • which editing mode you use? which version of jqGrid you use? You use `edittype:'custom'` which required specifying `custom_element` and `custom_value` callbacks in `editoptions` (see [the documentation](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#custom)). Could you include *full definition of the columns in `colModel`*? `editrules` used to validate the value and to display an error message. No changing of values will be done. The value of `maxValue` must be the number. No callback function is allowed. – Oleg Apr 13 '15 at 09:06
  • @Oleg - thanks for the quick response, added the details – SwissNavy Apr 13 '15 at 10:06
  • You are welcome! The code which you included contains some `function_for_element` and `function_for_value` without the implementation. I'm not sure that you really need `edittype : "custom"`. See [the demo](http://www.ok-soft-gmbh.com/jqGrid/ranking1_441.htm) from [the answer](http://stackoverflow.com/a/12744780/315935). One need to `edittype : "custom"` in case of really custom editing control. To be able to help you I need to know answers on the following questions: **which editing mode you use? which version of jqGrid you use?** – Oleg Apr 13 '15 at 10:20
  • @Oleg. jqGrid 4.4.1, cell editing mode. Yes, I skipped some parts that are irrelevant here. What I am trying to do is to set different maxValue for different rows on edit inside `$("#{{ grid_id }}").jqGrid` (which defines a row structure). I thought I can do it with a callback function. Let's say in the demo it's not editable pilot's name but an editable numeric field, and in the first row I don't allow to enter a number > 50 but in the second row it should prevent entering a number > 70, both with a standard error popup. I have a data["list_maxvalues"] list which I am passing from Django. – SwissNavy Apr 13 '15 at 10:41
  • @Oleg Now I have to attach those maxvalue limits to different rows in the table. And apparently `$("#{{ grid_id }}").jqGrid` object is not the right place to define this "maxvalue -by-row" limit. – SwissNavy Apr 13 '15 at 10:41

1 Answers1

0

The code which you use for column2 have absolutely wrong value for editrules. It seems that you mix the custom editing control with the validation rules.

The option under editrules will be used after the editing filed are read at the end of editing. If you use editrules: { number : true } then you can include additional properties minValue and maxValue inside of editrules. The values of minValue and maxValue must be numbers. To callback functions are allowed. Even if you would use custom validation rule then you can define editrules: {custom: true, custom_func: function mypricecheck (value, colname) {...}}, but even in the case the value is the string read from the input filed. No access to original input field (like $(elem).attr("maximum_discount_value") in your code) is possible here.

You can implement some other scenarios, but the code will depend on the editing mode which you use (inline editing, cell editing or form editing).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks a lot, I assumed that I could use callback functions for the keys in `editrules` just like I do in `editoptions`, turned out I was wrong. At least for the `maxValue` and `minValue` keys. Sorry can't upvote, need to collect some reputation first.. – SwissNavy Apr 13 '15 at 10:10