简体   繁体   English

如何在ember-cli应用程序中实现表单验证?

[英]How to implement form validation in ember-cli app?

I am developing a Ember-CLI app. 我正在开发一个Ember-CLI应用程序。 I have installed 我已经安装

  • ember-forms via bower 通过凉亭的余烬形式
  • ember-validations via npm 通过npm进行余烬验证

The form is generated properly. 该表格生成正确。 But the validations are not triggered. 但是不会触发验证。

{{#em-form model=controller class="col-md-5"}}
  {{em-input property="title" label="Title" placeholder="Title"}}
  {{em-text property="description" label="Description" placeholder="Description"}}
{{/em-form}}

The controller code with validations is 带有验证的控制器代码是

import Ember from "ember";

export default Ember.Controller.extend({
  actions: {
    submit: function() {
    }
  },
  validations: {
    title: {
      presence: true,
      length: { minimum: 5, maximum: 10 }
    }
  }
});

Any idea? 任何想法?

According to the docs "You need to mixin EmberValidations.Mixin into any Ember.Object you want to add validations to". 根据文档“您需要将EmberValidations.Mixin混入要向其中添加验证的Ember.Object中”。 It seems something like this would work: 看起来像这样会工作:

import Ember from "ember";
import EmberValidations from 'ember-validations';

export default Ember.Controller.extend(EmberValidations.Mixin, {
  actions: {
    submit: function() {
    }
  },
  validations: {
    title: {
      presence: true,
      length: { minimum: 5, maximum: 10 }
    }
  }
});

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

相关问题 如何在 React App 中实现全局表单验证? - How to implement a global form validation in React App? 如何在Vue应用程序(使用Vuetify.js)中实现验证的简单表单? - How to implement a simple form with validation in a Vue app (with Vuetify.js)? 使用ember.js进行字段和表单验证 - Field and Form Validation with ember.js 如何在提交表单之前对 Antd 字段进行 Validation - How to implement Validation on Antd field before submitting the form 易于实现的HTML5表单验证后备广告 - An easy to implement HTML5 Form Validation fallback 我的角度应用程序中没有表单验证 - No form validation in my angular app 如何实现表单对象 - How to implement form objects 如何在角度4中使用“ app-form-group-control-validation-display”显示“自定义验证”错误消息 - How to display Custom Validation error message using “app-form-group-control-validation-display” in angular 4 表单验证正则表达式和DOM:什么是在表单验证中实现正则表达式的最佳方法 - Form validation regex and DOM: What would be the best way to implement regex in a form validation MVC - 在哪里实现表单验证(服务器端)? - MVC - where to implement form validation (server-side)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM