[英]Add a sibling div to Ember Form For input element
I am using Ember Form For and I want to know if it is possible to add a sibling element. 我正在使用Ember Form For ,我想知道是否可以添加同级元素。
Currently doing this: {{f.radio-field "gender" "female"}}
当前正在这样做:
{{f.radio-field "gender" "female"}}
will render this: 将呈现此:
<div>
<label><input type="radio" value="female" />Female</label>
</div>
I need a container sibling element which I can add CSS pseudo classes to. 我需要一个容器同级元素,可以向其中添加CSS伪类。 I am unable to target parent containers of the input hence why I need a sibling element.
我无法定位输入的父容器,因此为什么需要同级元素。 So something like this is what I am after:
因此,我追求的是这样的事情:
<div>
<label>
<input type="radio" value="female" />
Female
<div class="someClass></div>
</label>
</div>
This addon seems to have support for custom components, it could be found in old docs and in source code 这个插件似乎支持自定义组件,可以在旧文档和源代码中找到
Theoretically, it should be possible to create your own component (ie my-radio-field
) by extending https://github.com/martndemus/ember-form-for/blob/master/addon/components/form-fields/radio-field.js and replacing layout
从理论上讲,应该可以通过扩展https://github.com/martndemus/ember-form-for/blob/master/addon/components/form-fields/radio来创建自己的组件(即
my-radio-field
) -field.js并替换layout
Component code: 组件代码:
import Component from 'ember-form-for/components/form-fields/radio-field';
import layout from 'my-project-name/templates/components/my-radio-field';
export default Component.extend({layout});
Template: 模板:
{{#form-field propertyName
class="radio-field"
classNames=fieldClasses
errorClasses=errorClasses
hintClasses=hintClasses
inputClasses=inputClasses
labelClasses=labelClasses
object=object
hint=hint
form=form
label=labelText
control=control
update=(action update) as |f|}}
{{#f.label required=required}}
{{f.control
option=value
accesskey=accesskey
autocomplete=autocomplete
autofocus=autofocus
autosave=autosave
dir=dir
disabled=disabled
hidden=hidden
lang=lang
list=list
required=required
tabindex=tabindex
title=title
}}
{{f.labelText}}
<div>Hello world</div>
{{/f.label}}
{{f.errors}}
{{f.hint}}
{{/form-field}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.