我如何提交一个实时验证的表单与语义UI和流星

How do I submit a real-time validated form with Semantic UI and Meteor?

本文关键字:表单 UI 流星 验证 语义 一个 何提交 提交 实时      更新时间:2023-09-26

我的表单遇到了一个巨大的问题,我使用Semantic UI实时验证。

HTML:

<form class="ui form pin-form">                     
  <div class="field">
    <label>Email</label>
    <input placeholder="name@example.com" name="email_input" type="text">
  </div>
  <div class="ui buttons">
    <input type="submit" class="ui submit positive disabled button login-button" value="Log in">
  </div>
</form>

我自己添加了<form>标签,并将提交放入input中,以便我可以访问常规的submit form

实时验证来自Semantic UI和一个Meteor包:https://github.com/avrora/live-form-validator

在模板渲染中,我这样做:

if (!this._rendered) {
this._rendered = true;
pinForm = $('.ui.form.pin-form');
pinForm.form({
    my_text_input: {
      identifier: 'email_input',
      rules: [
        {
          type: 'empty',
          prompt: 'Type your email address'
        },
        {
          type: 'email',
          prompt: 'This is not yet a valid email address'
        }
      ]
    }
  },
  {
    inline: true,
    on: 'blur',
    transition: 'slide down',
    onSuccess: function () {
      var submitButton = $('.ui.submit.button')
                submitButton.removeClass('disabled')
                return false
    },
            onFailure: function() {
                var submitButton = $('.ui.submit.button')
                submitButton.addClass('disabled')
            }
    })
}

这里的大问题是,return false它不提交的形式在所有,甚至当点击提交按钮,没有它提交的形式在实时,这是我不想要的!

任何人都可以看到一个解决方案,或者我需要以某种方式切换验证?

如果你想做一个Meteor.call,你可以尝试在onSuccess函数中做它。该软件包要求您在onSuccess函数中手动保存数据。

下面的代码记录了两次电子邮件。

onSuccess: function () {
    console.log("Email: ", $("input[name=email_input]").val());
    // Submit your form here using a Meteor.call maybe?
    return false;
},

你也可以查看aldeed:autoform来处理流星中的表单。

这可能是最愚蠢的问题了。(别担心,我问了这个问题,所以我只是在侮辱自己!)

语义UI实际上提供了on: change设置,它将实时验证表单,而不是现在设置的on: blur

哦,人…