0

I have a simple dropdown with two values.Lets say Staus:active and inactive. During the onchange event, I want to perfrom some validation and revert back if the validation fails. Thai is if I change from active-inactive and my validation fails, I should change the dropdown back to active. So far I am able to catch the on change event through the dataevents options of editOptions. Below is my code, Thanks for the assist.

editoptions:{value:{Y:'Active',N:'Inactive'}, dataEvents:[
                             {
                                 type: 'change',
                                 fn: function(e) {
                                 alert("inside change trigger");
                                 $grid.setColProp('Status', { editoptions:{value:{Y:'Active',N:'Inactive'}}});
                                 }
                              }
                         ]}

I also read I have to set recreate form :true. I tried that also.

user2375298
  • 1,001
  • 4
  • 15
  • 28

1 Answers1

0

I would recommend you to consider to make the column non-editable or to readonly/disabled if the validation condition could be checked before editing will be started. It shows the user more clear that the field mayn't be changed.

Alternatively you can get savedRow parameter of jqGrid if you use inline editing mode or cell editing mode (with var savedRows = $(this).jqGrid("getGridParam", "savedRow")). To get the "old" data in case of form editing you can just get the data of selected row by using getGridParam with selrow (or alternatively from the hidden field of the form which have id="id_g". Something like var serRowId = $("#id_g").val();) and by using getRowData/getCell.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks oleg, Is it possible that I can disable the dropdown options in that case except the first one. How will I make that column readonly in the initial stage. – user2375298 Nov 05 '14 at 10:52
  • @user2375298: You are welcome! See [the answer](http://stackoverflow.com/a/20498576/315935) for example for the corresponding demo. One can test `Status` of selected row inside of `beforeShowForm` and set `disabled` and `readonly` property (or `readonly="readonly"` and `disabled="disabled"` attributes) and add class `"ui-state-disabled"` to the row of editing form. – Oleg Nov 05 '14 at 11:50