jqGrid - 如何在编辑表单中隐藏字段 [英] jqGrid - how to have hidden fields in an edit form

查看:20
本文介绍了jqGrid - 如何在编辑表单中隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在用户尝试编辑行时将字段传递到编辑表单中,但我不希望这些字段可编辑 - 我希望它们只是被隐藏以便它们仍然被发送到服务器.

I want to be able to pass fields into the edit form when a user attempts to edit a row, but I don't want these fields to be editable - I want them to just be hidden so they still get sent to the server.

例如:

colModel :[
    {label: 'Game ID', name: 'game_id', editable:true},
    {label: 'Component ID', name: 'component_id', editable:true},
    {label: 'Table ID', name: 'table_id', editable:true},
],

这会将它们传递给编辑表单(因为 editable:true),但不幸的是,用户可以编辑它们.我想隐藏这些字段,以便用户无法编辑它们.

This will pass them to the edit form (because of editable:true) but unfortunately they will be editable by the user. I want to hide these fields so the user can't edit them.

我该怎么做?

推荐答案

编辑

好的,事实证明您可以将自定义元素定义为 编辑类型.根据您的情况,您可以执行以下操作:

Okay, turns out you can define a custom element as an edittype. For your situation, you'd do the following:

colModel :[
    {label: 'Game ID', name: 'game_id', editable:true, edittype:'custom',editoptions:{custom_element:myelem,custom_value:myval}},
    {label: 'Component ID', name: 'component_id', editable:true, edittype:'custom',editoptions:{custom_element:myelem,custom_value:myval} },
    {label: 'Table ID', name: 'table_id', editable:true, edittype:'custom',editoptions:{custom_element:myelem,custom_value:myval}}
]

然后你会像这样定义 myelemmyval:

Then you'd define myelem and myval like so:

function myelem(value,options){
   return $('<input type="text" value="'+value+'" disabled="disabled"/>');
}

function myval(elem){
    return elem.val();
}

这将构建一个禁用的文本字段,并且看起来不像 afterShowForm 那样 hack-ish.

This will construct a disabled text field, and seems less hack-ish than afterShowForm.

原创

如果您使用的是编辑表单控件(不是内联编辑),您似乎必须提供 afterShowForm 函数(向下滚动到事件部分).请参阅这个问题.

If you're using an edit form control (not inline editing), it looks like you have to provide an afterShowForm function (scroll down to the Events section). See this question.

您似乎希望列显示在视图中,但不可编辑.如果您设置 editable:true,那么用户无论如何都可以编辑该字段.您最终要做的是禁用/将表单元素设置为隐藏,以便用户无法更改它的值.afterShowForm 看起来像:

It looks like you want the columns to show up in the view, but not be editable. If you set editable:true, then the user can edit the field no matter what. What you'll end up having to do is disable / set the form element to hidden so the user can't change it's value. afterShowForm would then look something like:

afterShowForm: function(eparams){
    // change the selector appropriately
    $('#jqGrid input[name=game_id]').attr('type','hidden');
   // or $('#jqGrid input[name=game_id]').attr('disabled','disabled');
}

这篇关于jqGrid - 如何在编辑表单中隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆