How to configure beforeShowForm with lib.web.mvc to show non editable columns in add form

189 Views Asked by At

Some of my columns are not editable but I want all of the columns to display in the add form.

I was thinking that I can use the "beforeShowForm" event and call a javascript function that will dynamically change the column attribute back to editable so they will show up in the add form.

2

There are 2 best solutions below

0
tpeczek On BEST ANSWER

The typical approach for this is to make fields generally editable and hide them in edit dialog.

You can hide/show fields by looking for table rows which ids are being built like this:

tr_ColumnName

So in case you would have UserName column the id would be like this:

tr_UserName

Assuming you are using jQuery, you can wire-up this to your Lib.Web.Mvc configuration like this:

.Navigator(new Lib.Web.Mvc.JQuery.JqGrid.JqGridNavigatorOptions() { ... },
    editActionOptions: new Lib.Web.Mvc.JQuery.JqGrid.JqGridNavigatorEditActionOptions()
    {
        ...
        BeforeShowForm : "function(form) { $('#tr_UserName', form).hide(); }"
    },
    addActionOptions: new Lib.Web.Mvc.JQuery.JqGrid.JqGridNavigatorEditActionOptions()
    {
        ...
        BeforeShowForm : "function(form) { $('#tr_UserName', form).show(); }"
    }
);
0
Barry MSIH On

I figured how to use the event beforeShowForm.

Note: I have a using statement at the top of the view, so do not need to use the full namespace

@using Lib.Web.Mvc.JQuery.JqGrid 

Here is an example within the Navigator form:

.Navigator(new JqGrid.JqGridNavigatorOptions() 
{ Add = true, Edit = false, Delete = false, Search = false }, 
null, 
addActionOptions: new JqGridNavigatorEditActionOptions()
    {
        Url = Url.Action("Add"),
        BeforeShowForm = "function () {$('#bob').jqGrid('setColProp', 
        'Place', {editable:true})
    })