I’ve actually asked this question before, but haven’t achieved success with it back then, but I’m hoping this time round i’ll be luckier.
I’ve got a scenario where i need to have certain fields on a jqgrid modal remain populated after an add save action. (at the moment all the fields get cleared/reset to a default state). They’re not visible to the user, so when i try and save again, the validation prompts me to enter a date/manager/shift. I’ve tried various attempts to rectify this to noo success what so ever
I know its possible, as when a person edits and clicks save, the form does not get cleared. (I’m hoping i can do this selectively on the after save)
My screens look like this.
When adding

When Editing

The idea is when a user captures, they don’t need to update the date, shift & manager the whole time, as multiple records get captured against those sets of keys in one go, and it would be pretty annoying having to re-select those values on every go.
when adding takes place the form values get updated via the beforeShow hook. (and editing it’ll get ignored as i need to use the value in the grid, (in case a mistake was made)
Code snippet
DataGrid.navGrid('#pager', { edit: true, add: true, del: true, search: true },
editItems,
{
width: 600,
url: URL_add,
data: submit_data,
afterSubmit: function (result) {
success:
{
if (onAfterSubmit != null)
onAfterSubmit(result);
return Notify("success", result.responseText);
}
fail: { return Notify("error", result.responseText); }
},
recreateForm: true,
beforeShowForm: addBeforeShowOptions,
modal: false,
overlay: false,
jqModal: true
},
...
var addBeforeShowOptions = function (form) {
formPattern(form);
$('#Date', form).val($('#main_Date').val());
$('#Shift', form).val($('#main_Shift').val());
$('#ManagerID', form).val($('#main_Manager').val());
$('#tr_Date', form).hide();
$('#tr_ManagerID', form).hide();
}
I found another way of solving this, instead of injecting the values into the modal during editing, i’m updating the postData just before the data gets submitted by using the serializeEditData hook.
In my case it basically as simple as