【发布时间】:2014-04-22 03:57:29
【问题描述】:
我正在 ember.js 中写一个表单帖子。
- attr 绑定和条件仅支持除表达式以外的布尔值。
- 动作没有参数。
我希望仅在输入获得焦点且输入有效时显示错误。
简单来说,我应该在 focus-in 和 focus-out 属性中做到这一点。但是有这么多字段,我必须为每个输入编写两个动作。
我想写一个可重用的视图来做到这一点,但我不知道如何改变模型在视图中的值。
有人知道吗?
【问题讨论】:
标签: ember.js
我正在 ember.js 中写一个表单帖子。
我希望仅在输入获得焦点且输入有效时显示错误。
简单来说,我应该在 focus-in 和 focus-out 属性中做到这一点。但是有这么多字段,我必须为每个输入编写两个动作。
我想写一个可重用的视图来做到这一点,但我不知道如何改变模型在视图中的值。
有人知道吗?
【问题讨论】:
标签: ember.js
Erp.FromFieldView = Ember.TextField.extend({
attributeBindings: ['type', 'value', 'size', 'pattern', 'name', 'min', 'max',
'accept', 'autocomplete', 'autosave', 'formaction',
'formenctype', 'formmethod', 'formnovalidate', 'formtarget',
'height', 'inputmode', 'list', 'multiple', 'pattern', 'step',
'width', 'error', 'regex'],
name: 'default',
error: '',
regex: '^.+$',
isValid: true,
valueChanged: function () {
re = new RegExp(this.get('regex'), 'g');
this.set('error', !re.test(this.get('value')));
}.observes('value'),
focusIn: function (event) {
this._super(event);
if (this.get('value') == undefined) {
this.set('error', true);
}
},
focusOut: function (event) {
this._super(event);
this.set('error', false);
}
});
Ember.Handlebars.helper('form-field', Erp.FromFieldView);
【讨论】: