【问题标题】:How would I disable the 5 same fields of specific forms in a formset?如何禁用表单集中特定表单的 5 个相同字段?
【发布时间】:2009-03-23 21:47:24
【问题描述】:

某些表单代表父对象,如果它们用于“父”对象,我希望在每个表单中禁用大多数字段。有没有简单的方法可以做到这一点?

【问题讨论】:

    标签: django-forms


    【解决方案1】:

    最简单的方法是给字段一个特定的语义类,然后使用jQuery 禁用该类的所有字段。假设这些表单都包含在一个 ID 为 formgroup 的较大容器中,并且您使用 dependent-field 作为类名,您可以使用以下内容:

    // Set the 'disabled' attribute on every dependent field in this group of forms.
    $('#formgroup').find('.dependent-field').attr('disabled', true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      • 2013-04-03
      • 2016-09-28
      • 2013-09-13
      • 2023-03-09
      相关资源
      最近更新 更多