| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 1 |
+'use strict'; |
|
| 2 |
+ |
|
| 3 |
+module.exports = {
|
|
| 4 |
+ name: 'select', |
|
| 5 |
+ template: require('../../templates/components/select.tpl'),
|
|
| 6 |
+ style: require('../../styles/clay/components/select.scss'),
|
|
| 7 |
+ manipulator: 'val', |
|
| 8 |
+ defaults: {
|
|
| 9 |
+ label: '', |
|
| 10 |
+ options: [], |
|
| 11 |
+ description: '', |
|
| 12 |
+ attributes: {}
|
|
| 13 |
+ }, |
|
| 14 |
+ initialize: function() {
|
|
| 15 |
+ var self = this; |
|
| 16 |
+ |
|
| 17 |
+ var $value = self.$element.select('.value');
|
|
| 18 |
+ |
|
| 19 |
+ /** |
|
| 20 |
+ * Updates the HTML value of the component to match the slected option's label |
|
| 21 |
+ * @return {void}
|
|
| 22 |
+ */ |
|
| 23 |
+ function setValueDisplay() {
|
|
| 24 |
+ var selectedIndex = self.$manipulatorTarget.get('selectedIndex');
|
|
| 25 |
+ var $options = self.$manipulatorTarget.select('option');
|
|
| 26 |
+ var value = $options[selectedIndex] && $options[selectedIndex].innerHTML; |
|
| 27 |
+ $value.set('innerHTML', value);
|
|
| 28 |
+ } |
|
| 29 |
+ |
|
| 30 |
+ setValueDisplay(); |
|
| 31 |
+ self.on('change', setValueDisplay);
|
|
| 32 |
+ } |
|
| 33 |
+}; |