blob: b708fc48b11d2fe9b5542e9d118ce09703d6ce2f [file] [log] [blame]
The res/common/js/common.js file must be included before this file.
This in an HTML Import-able file that contains the definition
of the following elements:
This element adds a clear button and a selected-values binding to a select element.
To use this file import it:
<link href="/res/imp/select-status-sk.html" rel="import" />
values - Array of Strings. The selected values.
clear - Boolean. If there should be a clear button as well.
setTarget(targetSelect) - Should be called to bind this to a select element. targetSelect should be a dom element.
<dom-module id="select-status-sk">
<button id="clear" on-click="clearSelections" hidden$="{{!clear}}">Clear</button>
is: 'select-status-sk',
properties: {
clear: {
type: Boolean,
value: false,
values: {
type: Array,
notify: true,
observer: "applySelection"
// no default value here to allow parent to supply the value from another binding.
// applySelection handles input from the parent element via the binding,
// updating the select element to mirror the selection.
applySelection: function(selection) {
if (!selection) {
$$('option', {
option.selected = (selection.indexOf(option.value) != -1);
}, this);
// _updateSelection handles input from the user on the select element.
_updateSelection: function() {
var selected = [];
$$('option', {
if (option.selected) {
}, this);
// This is just an array of values, so we don't need to use this.push/this.splice
// In fact, such methods do not properly update the host.
this.set("values", selected);
clearSelections: function() {
$$('option', (elem) {
elem.selected = false;
// target should be a select element, e.g. this.$.select, from the parent. It used to be a
// string, and in the attached() callback of select-status, we would look for $('#' + target)
// and save that as However, this does not work in most cases because the
// attached of the select was typically after the attached of the parent and the target
// select had not been stamped out yet.
setTarget: function(target) { = target;
this.applySelection(this.values);'change', this._updateSelection.bind(this));