【问题标题】:Created forms from JSON Schema, How to add Close button?从 JSON Schema 创建的表单,如何添加关闭按钮?
【发布时间】:2013-12-04 06:53:12
【问题描述】:

有了这个https://github.com/joshfire/jsonform,我创建了表单。

$('form').jsonForm({
    schema: {
        name: {type: 'string', title: 'Name', required: true},
        //age: {type: 'number', title: 'Age', required: true},
        comment: {type: 'textarea', title: 'Comments', required: true},             
        choice: {type: 'string',title: 'Title', 'enum': ['choice-1','choice-2','choice-3']},

    },          
    onSubmit: function (errors, values) {
      if (errors) {
        $('#res').html('<p>I beg your pardon?</p>');
      }
      else {
        $('#res').html('<p>Hello ' + values.name + '.' +
          (values.comment ? '<br/>You are ' + values.comment + '.' : '') +
          '</p>');
      }
    }
}); 

在这个默认提交按钮是存在的。

但我想添加“关闭”按钮。

或者我如何删除或隐藏默认的“提交”按钮,以便我添加其他提交和关闭按钮?

【问题讨论】:

  • 考虑覆盖 jsonform 并在隐藏默认提交按钮时自己添加关闭按钮。
  • 我认为添加自定义按钮的文档并不简单。 @eegloo 在下面查看我关于添加自定义按钮的答案。
  • @srvikram13 :感谢您的回答。 “.form-actions {display:none;}”添加到 CSS 文件中。这也有效
  • @Pedram Behroozi:是的,我有这个链接,谢谢。但有些部分并不直截了当。这就是为什么困惑。在 CSS 中添加了“.form-actions {display:none;}”。

标签: javascript jquery json jquery-ui getjson


【解决方案1】:
$('form').jsonForm({
    ...code
}); 
// Save reference to parent element to append custom buttons
var btn-container = $('form input[type=submit]').parent();

// Remove default 'submit' button
$('form input[type=submit]').remove();

// now add custom buttons in btn-container

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 2015-01-23
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    相关资源
    最近更新 更多