Hi,
I would like to have a read-only field when I add a new record.
I have tried this function where it will show "Test Value" when I add a new record.
$col["editoptions"] = array("defaultValue"=>"Test Value","readonly"=>"readonly", "style"=>"border:0");
Now, the value that I would like to have is pre-determined from database instead of user defined.
For Example, from the demo of Master Detail Fancy, when I add a new record in Invoice Data (detail grid). I would like to show the client_id as read only which was pre-determined from master grid from database.
What would be the function to get this?
Many Thanks,
John
Please refer attached demo:
http://hastebin.com/culaqoliya.php
2 main changes for your scenario:
// fill detail add form, with parent id
$opt["add_options"]["afterShowForm"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); $('#client_id').val(jQuery('#list1').jqGrid('getCell', selr, 'client_id')); }";
// set detail form client_id as readonly and for add dialog only
$col["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
$col["show"]["edit"] = false;
Hi Abu,
Its working great!!!,
However, what if I would like to have 2 or more field as read-only when I add new record?
the value would be predefined from the master grid as well.
Many Thanks,
John
It will be same process, just like client_id, e.g. invdate that is column of list1 and need to be readonly in detail.
$opt["add_options"]["afterShowForm"] = "function(formid){
var selr = jQuery('#list1').jqGrid('getGridParam','selrow');
$('#client_id').val(jQuery('#list1').jqGrid('getCell', selr, 'client_id'));
$('#invdate').val(jQuery('#list1').jqGrid('getCell', selr, 'invdate'));
}";
And same will following with column definition $col of invdate.
$col["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
$col["show"]["edit"] = false;