当前位置: 首页 > 软件库 > 程序开发 > >

ember-form-for

授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 楚嘉胜
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Ember Form For

This Ember.js addon will give you an easy way to build good forms:

WARNING: This addon uses contextual helpers and is therefore onlycompatible with apps built with Ember.js version 2.3 and up.

NOTE: I'm working on rewriting docs, click here for the old docs!

Installation

ember install ember-form-for

Quickstart Example

{{#form-for newUser as |f|}}
  {{f.text-field "firstName"}}
  {{f.text-field "lastName"}}

  {{#fields-for newUser.address as |fa|}}
    {{fa.text-field "street"}}
    {{fa.text-field "city"}}
    {{fa.text-field "state"}}
    {{fa.text-field "zipCode"}}
  {{/fields-for}}

  {{f.select-field "gender" "unknown male female"}}

  {{f.date-field "birthDate"}}

  {{f.email-field "emailAddress"}}
  {{f.text-field "userName"}}
  {{f.password-field "password" hint="Must be at least six characters long and include a capital letter"}}

  {{f.checkbox-field "terms" label="I agree to the Terms of Service"}}

  {{f.reset  "Clear form"}}
  {{f.submit "Create account"}}
{{/form-for}}

See this example in action: http://martndemus.github.io/ember-form-for/

Breaking down the quickstart example

Let's first take a look at the form-for component itself:

{{#form-for newUser as |f|}}
  {{! form fields go here }}
{{/form-for}}

The {{form-for}} component takes an object as first parameter, newUser inthis case, this is the object where the form fields will be created for.

It then yields f, f contains all form controls as contextual components.This means that the components rendered with f already have form-for'scontext applied to it, you don't have to pass the target object to eachform control, form-for takes care of that.

For example {{f.text-field "firstName"}} will render an input that will updatethe firstName property of the newUser object you have passed to theform-for component. You didn't have to pass newUser again, because it's takenfrom form-for's context.

Next you see the {{fields-for}} component. This component is similar toform-for, except it doesn't render a <form> element as outer element, thisis ideal to embed subsections to your form that operate on a different object.

Lastly there are the {{f.reset}} and {{f.submit}} button components. Theseare getting passed the reset and submit action from the form-for componentrespectively. By default the reset action will call the rollback function onthe object, the submit action will call the save function on the object.

Table of Contents

Reference

form-for

The {{form-for}} component is the main component from this addon. All formsbuilt with this addon should start with this component.

Syntax

{{#form-for object
    update=(action update)
    submit=(action submit)
    reset=(action reset)
    as |f|
}}
  {{! block content }}
{{/form-for}}

Parameters

object

The object the form fields are for

update

This action is called every time a field is updated. It will pass threearguments: object, property and value. By default it will automaticallyupdate the property on the object with the new value.

submit

This action is called when a submit button is clicked. It will pass the objectas first argument. By default it will call the save function on the object.This action also supports returning a promise, which the {{f.submit}} component.

reset

This action is called when a reset button is clicked. It will pass the objectas first argument. By default it will call the rollback function on theobject.

Yields

formControls

An object containing form controls as contextual components.The form controls have the object and the update action pre-bound to it.

The default form controls are:

  • checkbox-field
  • color-field
  • date-field
  • datetime-local-field
  • email-field
  • file-field
  • hidden-field
  • month-field
  • number-field
  • password-field
  • radio-field
  • radio-group
  • range-field
  • search-field
  • select-field
  • tel-field
  • text-field
  • textarea-field
  • time-field
  • url-field
  • week-field
  • custom-field

Additionally these buttons are also available:

  • button
  • reset
  • submit

form-fields

The form-field components are yielded from the {{form-for}} component. All theavailable form-field components are described in the form-for section.

Syntax

{{#form-for object as |f|}}
  {{f.text-field "propertyName"}}
{{/form-for}}

Parameters

object

The object the form field is for. By default object is the object passed tothe {{form-for}} component, but you can override it if you want to.

propertyName

This tells the form field which property of the object to use as value. Can bepassed as the first positional param.

update

The action that handles updates to the value of the form-field by the user. Bydefault this action is passed down from the {{form-for}} component.

label

The text value for the label of the form-field. By default is inferred from thepropertyName attribute or lookup up from the i18n service if available.

hint

Text to be displayed along the control as a hint to the user.

required

If set to true it will mark the field as required.

Integrations

i18n

Ember Form For has out of the box support forember-i18n. If your project hasthis addon installed, it will automatically lookup the translation with thefollowing key algorithm:

  • By default it will use property-name as key. (e.g. 'first-name').
  • If modelName is set, or deducable from the object, then it will beprefixed to the key. (e.g. 'user.first-name')
  • If i18nKeyPrefix is set on the config, then this will be prefixed beforemodelName and propertyName. (e.g. 'my.arbitrary.key.user.first-name')

Polyfilling i18n

The project does not have a hard dependency on ember-i18n, you can easilydrop-in your own implementation. All you need is a service called i18n thathas a function called t.

ember-changeset

It's easy to integrateember-changeset andember-changeset-validationswith Ember Form For. All you have to do is to pass the changeset into the{{form-for}} helper instead of the raw object:

{{#form-for (changeset model validations) as |f|}}
  {{! form fields }}
{{/form-for}}

Errors

To be able to use the errors generated by ember-changeset you need to configurethe following thing in your config/environment.js file:

module.exports = function(environment) {
  var ENV = {
    'ember-form-for': {
      errorsPath: 'error.PROPERTY_NAME.validation',
    }
  };

  return ENV;
};

This is because ember-changeset stores it's errors on the error.PROPERTY_NAME.validation property,while Ember Form For expects them (by default) to be on the errors property.

For those still using the old configuration of setting errorsProperty, this method will still work.However, if both are defined then errorsPath will take precedence.

  • 转自:http://www.cnblogs.com/CiWEi-/archive/2011/12/25/2300854.html 一、建noTab的Folder Form: 1.创建数据库对象:   create table  和相应的view。 2.基于模板Template.fmb创建一个新的Form:****.fmb   添加一个Library:APPFLDR.pll(目录:$AU_TOP/R

  • 理解动态网和静态网页区别 动态网页技术:能够实现交互,就叫动态网页技术 交互:能够与后台交换数据(例如:ajax,node.js php java等) 静态网页技术:不能实现交互 javascript,jquery都是静态网页,不过是实现静态网页上的动态效果 表单的典型应用 注册用户 收集信息 反馈信息 搜索引擎 表单的基本结构 <form action="http://www.baidu.com

  • 使用emap进行开发的时候,emapForm使用极为频繁,其中有不少比较坑的东西,由于使用文档不是很清楚,所以结合自己的使用经验进行一个总结。 参考资源: http://res.wisedu.com/FS/docsite/emapcomponent.html http://res.wisedu.com/examples/components-v1/docs/emap/v1.1/emapForm.j

  • 类全称: Ext.form.FieldSet 继承自于: Ext.Panel 针对某一组字段的标准容器。  配置项   1、checkboxToggle : Mixed  True表示在lengend标签之前fieldset的范围内渲染一个checkbox,或者送入一个DomHelper的配置对象制定 checkbox(默认为false)。选择该checkbox会为展开、收起该面板服务。  2、c

  • form的主要作用: 1.在html中生成表单框架,2.验证数据 https://www.cnblogs.com/zongfa/p/7709639.html 1.在model里创建一些数据类型 class Users(models.Model): uname = models.CharField(max_length=30,unique=True,verbose_name="用户名")

 相关资料
  • ember-validated-form-buffer ember-validated-form-buffer implements a validating buffer that wraps EmberData models and can be used in forms to buffer user inputs before applying themto the underlying

  • 1.7.0 新增 从 1.8.0 开始支持blur 时才触发校验以及 debounce,同 Validator 一样也开始支持异步校验。 表单,包含各种输入组件以及对应的校验;我们可以通过数据驱动的方式来生成完成表单。 示例 默认配置使用 一个完整的包含所有的内置表单相关组件。 <cube-form :model="model" :schema="schema" :immediate-

  • 此方法返回'NUMERIC FORM'的当前设置,该设置用于在系统上进行数学计算。 语法 (Syntax) FORM() 参数 (Parameters) 没有 返回值 (Return Value) 此方法返回'NUMERIC FORM'的当前设置,该设置用于在系统上进行数学计算。 例子 (Example) /* Main program */ say FORM() 当我们运行上述程序时,

  • 在大多数Web应用程序中,表单是从用户获取信息的最重要的小部件,例如登录表单/反馈表单,以便可以将值保存在数据库中以供将来参考。 表单窗口小部件用于此目的。 在创建表单之前,我们应该了解xTypes。 xType定义Ext JS UI组件的类型,该组件在呈现组件期间确定。 例如,元素可以是我们将xType作为textField的文本框,或者元素只能具有我们具有Numeric xType的数值。 不

  • 介绍 (Introduction) Form容器允许您控制表单的布局,根据需要或可选标记表单字段,处理错误消息,以及将表单数据绑定到Flex数据模型以执行数据检查和验证。 它还允许您使用样式表来配置表单的外观。 Class 声明 (Class Declaration) 以下是spark.components.Form类的声明 - public class Form extends Cont

  • form 表单,将组件内的用户输入的 <switch/> <input/> <checkbox/> <slider/> <radio/> <picker/> 提交。 当点击 <form/> 表单中 formType 为 submit 的 <button/> 组件时,会将表单组件中的 value 值进行提交,需要在表单组件中加上 name 来作为 key。 属性名 类型 说明 report-subm