【问题标题】:Meteor: Bootstrap data-dismiss=‘modal’ preventing autoform submissionMeteor: Bootstrap data-dismiss='modal' 阻止自动提交
【发布时间】:2016-02-07 05:05:20
【问题描述】:

所以我在 Meteor 中使用了 autoform 和 bootstrap 包。目标是能够在引导模式内使用 autoform 创建自动生成的表单,然后单击提交按钮创建一个新对象以添加到集合中并关闭模式。

我遇到的问题是,当我将data-dismiss="modal" 添加到提交按钮时,它将停止提交到集合并关闭模式。对正在发生的事情有任何想法吗?

我的模态模板如下所示。

<template name="goalCreationModal">
    <div class="modal fade">
        <div class="modal-dialog">
            <div class="modal-content">

                <div class="modal-header">
                    <h4 class="modal-title">Modal example</h4>
                </div>

                <div class="modal-body">

                     <p> ---- </p>
                     {{#autoForm collection="Goals" id="insertGoalForm" type="method" meteormethod="addGoal"}}
                        <legend>Add a Goal</legend>
                        {{> afQuickField name='title'}}
                        {{> afQuickField name='color'}}
                        <button type="submit" class="btn btn-default make-goal" data-dismiss="modal">Submit</button>
                    {{/autoForm}}
                </div>

                <div class="modal-footer">
                </div>
        </div>
    </div>
</div>

【问题讨论】:

    标签: bootstrap-modal meteor-autoform


    【解决方案1】:

    我遇到了同样的问题。解决方案是这样的:

             {{#autoForm schema="PostsSchema" id="insertPost" type="method" meteormethod="postEntry"}}
                   <div class="modal-body">
                        <fieldset>
                          {{> afQuickField name='title'}}
                          {{> afQuickField name='user' type = 'hidden'}}
                          {{> afQuickField name='content' rows=10}}
                          {{> afQuickField name='tag'}}
                        </fieldset>
    
    
                   </div><!-- / modal-body -->
    
    
                    <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Ask</button>
                      <button class="btn btn-warning" data-dismiss="modal">
                        Close
                      </button>
                    </div><!-- / modal-footer -->
                    {{/autoForm}}
    

    注意 {{autoform}} 标签。试试这个代码,它对我有用。

    【讨论】:

    • 嗨 Stefan,我尝试按照您的建议包装 autoform 标签。它似乎没有任何影响。这是我所做的链接:example
    • 现在,检查三件事。首先,检查简单模式中的字段。确保您在模板中具有所有字段或在架构中具有(可选:true;)。其次,放置fieldset标签。第三,确保您没有调用 Template.events 中的任何方法(当您单击提交时,表单会自动调用您在 autoform 标签中指定的方法)。
    • 我认为我的架构没有任何问题,当我删除 data-dismiss 属性时,目标提交就好了。我确信事件的触发或捕获方式存在问题。我目前解决这个问题的方法是在点击事件上手动调用Modal.hide('goalCreationModal');
    猜你喜欢
    • 2018-11-27
    • 2014-08-04
    • 2018-07-02
    • 2013-02-24
    • 2015-09-12
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    相关资源
    最近更新 更多