Files
clay/src/scripts/components/select.js
T

35 lines
888 B
JavaScript

'use strict';
module.exports = {
name: 'select',
template: require('../../templates/components/select.tpl'),
style: require('../../../tmp/select.css'),
manipulator: 'val',
defaults: {
label: '',
options: [],
serializeValueAs: 'string',
description: '',
attributes: {}
},
initialize: function() {
var self = this;
var $value = self.$element.select('.value');
/**
* Updates the HTML value of the component to match the selected option's label
* @return {void}
*/
function setValueDisplay() {
var selectedIndex = self.$manipulatorTarget.get('selectedIndex');
var $options = self.$manipulatorTarget.select('option');
var value = $options[selectedIndex] && $options[selectedIndex].innerHTML;
$value.set('innerHTML', value);
}
setValueDisplay();
self.on('change', setValueDisplay);
}
};