【问题标题】:How to have different edit options for add & edit forms in jqGrid如何在 jqGrid 中为添加和编辑表单提供不同的编辑选项
【发布时间】:2010-01-01 04:32:35
【问题描述】:

我有一个 jqGrid,其中包含要在表单中编辑的用户信息。用户名是不可变的,但应该出现在表单中,以便用户知道他们正在编辑哪个用户。密码只能编辑。所以在我的 colModel 我有这样的设置:

{name:'username', index:'username', width:155, editable:true, editoptions: {readonly:'readonly'}}, 
{name:'password', index:'password', width:155, hidden:true, editable: true, edittype:'password', editrules:{edithidden:true}}, 

这适用于编辑。我的问题是添加我需要将用户名设置为“非只读”。我没有看到控制添加表单和编辑表单的属性。也许我可以使用afterShowForm 事件来更改编辑选项?有人做过这样的事吗?

【问题讨论】:

    标签: jquery forms jqgrid


    【解决方案1】:

    如果它对其他人有用,我无法完全做到这一点,但找到了一种方法来完成最终结果。

    因此,我没有使用 editoptions 将表单字段设置为只读,而是使用添加和编辑选项的 beforeShowForm 事件来添加和或删除只读属性。

    所以没有只读的colmodel:

    {name:'username', index:'username', width:155, editable:true}, 
    {name:'password', index:'password', width:155, hidden:true, editable: true, edittype:'password', editrules:{edithidden:true}}, 
    

    和 navGrid 编辑和添加选项可打开(用于添加)或关闭(用于编辑)只读。注意,INPUT 标签的 ID 将是 colModel 中 name 字段的值:

    jQuery("#user-grid").jqGrid('navGrid','#user-grid-pager',
        { }, //options
        { // edit options
            beforeShowForm: function(frm) { 
                $('#username').attr('readonly','readonly'); 
            }
        }, 
        { // add options
            beforeShowForm: function(frm) { 
                $('#username').removeAttr('readonly'); 
            }
        }, 
        { }, // del options
        { } // search options
    );
    

    附带说明,虽然我知道(根据 jquery dump)“frm”函数 arg 是一个包含表单的 jQuery 对象,但我无法获得选择器来成功选择我想要的孩子,所以我只使用了 id与 colModel 名称匹配。

    【讨论】:

    • 只是想说声谢谢 - 我有完全相同的要求,但我不知道如何调用 beforeShowForm 函数。这正是我所需要的 - 再次感谢。
    • 同上。感谢您的发表。它为我节省了大量时间。
    【解决方案2】:

    这可以通过内置的 jqgrid 选项实现。

    http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules

    hidden:true, editrules:{editithidden:true, required:true....}, editable:true

    所以你可以让field_name可编辑:false,field_id如上

    这也涵盖了选择框的另一个问题,也适用于它们

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      相关资源
      最近更新 更多