diff --git a/README.md b/README.md index a823484..eb58c7a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Dropdown menu with search and multiple options selection * autoValidate - boolean +* customObjectOptions - Boolean, Default: false * disabled - Boolean Default: false * dynamicAlign - Boolean Default: false * emptyValue - Boolean Default: false @@ -16,14 +17,19 @@ Dropdown menu with search and multiple options selection * label - String * menuOpened - Boolean Default: false – notifies * multi - Boolean Default: false +* noChangeEvent - Boolean, Default: false +* optionLabel - String, Default: label * options - Array +* optionValue - String, Default: 'value' * placeholder - string * required - boolean * search - String +* selected - Number/Array - notifies * selectedValues - Object notifies * showLimitWarning - Boolean * shownItems - Array * shownItemsLimit - Number Default: 50 +* updateSelected - Boolean, Default: false * value - String ## Usage @@ -121,6 +127,54 @@ this.$.dropdownElement.validate(); this.$.dropdownElementMulti.validate(); ``` +If the options array where objects of this model: `{value: someIntegerValue, label: someLabel}` +is not what you need you can use any type of objects. You have to set some properties on the element to tell +that you have custom options and which properties to be used as values and labels. +```javascript +// options example(used in the demo), in properties object +customObjOptions: { + type: Array, + value: function() { + var opt = []; + for(var i = 1; i <= 100; i++) { + opt.push({ + id: i, + option_key: 'opt' + i, + option_label: 'Option ' + i, + some_other_propery: 'dummy propery for objIdx' + (i -1) + }); + } + return opt; + } +} +``` +```html + +``` + +If you need only select an option and get option ID (most use cases) or an array of IDs(for multiselection) +you can use `selected` property of the element. It only works for integer values, for other types use `selectedValues` property. +Additionally you can chose to block the change event. Example: + +```html +

SelectedID: [[selectedId]]

+ + +``` + ## Styling Use this css variables and mixins to style this element. diff --git a/bower.json b/bower.json index 1640b81..dde5b2d 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "etools-searchable-multiselection-menu", "description": "Dropdown menu with search and multiple options selection", - "version": "1.0.18", + "version": "1.0.20", "license": "https://github.com/unicef-polymer/etools-searchable-multiselection-menu/blob/master/LICENSE.md", "main": "etools-searchable-multiselection-menu.html", "dependencies": { diff --git a/deletable-option-list.html b/deletable-option-list.html index 3c91838..fcbafc1 100644 --- a/deletable-option-list.html +++ b/deletable-option-list.html @@ -2,94 +2,116 @@ - - + + _fireClose: function(e) { + if (this.disabled) { + return; + } + var details = e.model.item; + var removedItemStrValue = (details[this.optionValueAttribute]) + ? (details[this.optionValueAttribute] + '') : ''; + var newValue = this.optionValue.filter(function(item) { + if (this.customObjectOptions) { + var optValue = (item[this.optionValueAttribute]) ? (item[this.optionValueAttribute] + '') : ''; + return optValue !== removedItemStrValue; + } else { + return parseInt(item[this.optionValueAttribute], 10) !== parseInt(details[this.optionValueAttribute], 10); + } + }.bind(this)); + newValue = newValue.length > 0 ? newValue : null; + this.set('optionValue', newValue); + this.fire('option-delete', details); + }, + }); + diff --git a/demo/demo-custom-objects-as-options.html b/demo/demo-custom-objects-as-options.html new file mode 100644 index 0000000..92559ec --- /dev/null +++ b/demo/demo-custom-objects-as-options.html @@ -0,0 +1,170 @@ + + + + + + + diff --git a/demo/index.html b/demo/index.html index 69954b2..22b7c42 100644 --- a/demo/index.html +++ b/demo/index.html @@ -13,6 +13,7 @@ +