简体   繁体   English

用流星自动预览功能预览数据

[英]Previewing data with meteor-autoform

I have a tabbed page layout with a form and a preview. 我有一个带有表单和预览的选项卡式页面布局。 Is there any way to validate a form with pushing the 'Preview' button, and to switch to the second tab once it's valid? 是否有任何方法可以通过按下“预览”按钮来验证表单,并在有效后切换到第二个选项卡? Ie we are not creating anything until the 'Submit' button is pressed. 也就是说,在按下“提交”按钮之前,我们不会创建任何内容。

<div class="tab-content">
    <div class="tab-pane text-left fade in active" id="compose">
        {{#autoForm collection="Jobs" id="insertJobForm" type="insert"}}
            {{> afQuickField name="title" class="form-control input-lg"}}
            [more fields]
            <div class="form-group">
                <button type="submit">Preview</button>
            </div>
        {{/autoForm}}
    </div>
    <div class="tab-pane text-left" id="preview">
        <h2>{{currentFieldValue "title"}}</h2>
        [more output]
        <button type="submit">Submit</button>
    </div>
</div>

You can trigger the autoform's validation with AutoForm.validateForm('yourFormIdGoesHere') and extract the values with Autoform.getFormValues(yourFormIdGoesHere) or can simply serialise the form. 您可以使用AutoForm.validateForm('yourFormIdGoesHere')触发自动AutoForm.validateForm('yourFormIdGoesHere')的验证,并使用Autoform.getFormValues(yourFormIdGoesHere)提取值,也可以简单地序列化表单。

Then you use the values as the data context to the preview templates: {{>previewTemplate formData}} you need to create a template helpers for this. 然后,您将这些值用作预览模板的数据上下文: {{>previewTemplate formData}}需要为此创建模板帮助器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM