Read Only in add record dialog

QuestionsRead Only in add record dialog
John asked 10 years ago

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

3 Answers
Abu Ghufran answered 10 years ago

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;

John answered 10 years ago

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

Abu Ghufran answered 10 years ago

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;

Your Answer

13 + 15 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?