[英]Polymer IronFormElementBehavior in custom element
I'm using a custom date picker ( https://github.com/bendavis78/paper-date-picker ). 我正在使用自定义日期选择器( https://github.com/bendavis78/paper-date-picker )。 It works fine, but what I'd like to do is tie it to a paper-input, so whenever the input is clicked, the dialog shows.
它工作正常,但我想做的就是将其绑定到纸张输入上,因此,每当单击输入时,都会显示对话框。 I got that working by creating a custom element.
我通过创建自定义元素来完成该工作。 My problem now, is that I need this element in an iron form, so I can send the date along with an ajax request.
我现在的问题是,我需要用铁的形式表示此元素,因此我可以将日期和ajax请求一起发送。 I've found that I need my custom element to extend the Polymer.IronFormElementBehavior, but I can't find any documentation on how to actually do that.
我发现我需要我的自定义元素来扩展Polymer.IronFormElementBehavior,但是我找不到有关如何实际执行操作的任何文档。 The example just slaps it on a regular input element, so there is no useful context there.
该示例仅将其放在常规输入元素上,因此那里没有有用的上下文。 Here is my custom element with my attempt to implement the behavior:
这是我尝试实现该行为的自定义元素:
<link rel="import" href="../../vendor/iron-form-element-behavior/iron-form-element-behavior.html">
<dom-module id="datepicker">
<template>
<style>
</style>
<paper-input id="input" label="[[label]]" on-tap="openDatePicker" value="{{inputValue}}">
<iron-icon icon="date-range" prefix></iron-icon>
</paper-input>
<paper-dialog id="datePickerDialog" class="paper-date-picker-dialog" name="dumb" modal on-iron-overlay-closed="_onDialogClosed">
<paper-date-picker id="datePicker"></paper-date-picker>
<div class="buttons">
<paper-button dialog-dismiss>Cancel</paper-button>
<paper-button dialog-confirm>OK</paper-button>
</div>
</paper-dialog>
</template>
</dom-module>
<script>
Polymer
({
is: "datepicker"
, behaviors:
[
Polymer.IronFormElementBehavior
]
, properties:
{}
, ready: function ()
{
this.$.name = this.name;
}
// Custom functions //
, _onDialogClosed: function(event)
{
if (event.detail.confirmed)
{
var date = new Date(this.$.datePicker.date);
this.inputValue = moment(date).format("LL");
this.$.value = this.inputValue;
}
}
, openDatePicker: function()
{
this.$.datePickerDialog.open();
}
});
I can't get the date value to show up in the post data, though. 但是,我无法获得日期值显示在帖子数据中。 The behavior has a name and value property, and I feel like all I need to do is tie those to my paper-input, but that doesn't seem to do anything.
该行为具有名称和值属性,我觉得我所需要做的就是将它们绑定到我的纸张输入上,但这似乎无济于事。
Has anyone actually successfully implemented this behavior? 有人真的成功实现了此行为吗? Am I missing something?
我想念什么吗?
I ran into the same issue. 我遇到了同样的问题。 The property name 'value' is special.
属性名称“值”是特殊的。
iron-input adds the bind-value property that mirrors the value property, and can be used for two-way data binding.
iron-input添加了绑定value属性,该属性反映了value属性,并且可用于双向数据绑定。 bind-value will notify if it is changed either by user input or by script.
绑定值将通知它是通过用户输入还是通过脚本进行更改。
Currently you are using a property 'inputValue'. 当前,您正在使用属性“ inputValue”。 This should be changed to 'value'.
应该将其更改为“值”。
Your custom element needs to: 您的自定义元素需要:
value
property in the initial definition value
属性 Update the code on change to this.value
instead of this.inputValue
在更改时将代码更新为
this.value
而不是this.inputValue
Polymer ({ is: "datepicker" 聚合物({是:“日期选择器”
, behaviors: [ Polymer.IronFormElementBehavior ] , properties: { value : { type: String, value: "Default value" } } , ready: function () { this.$.name = this.name; } // Custom functions // , _onDialogClosed: function(event) { if (event.detail.confirmed) { var date = new Date(this.$.datePicker.date); // Update this to just "value" this.inputValue = moment(date).format("LL"); this.$.value = this.inputValue; } } , openDatePicker: function() { this.$.datePickerDialog.open(); }
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.