stimulus_reflex
Advanced tools
Comparing version 1.0.2 to 1.1.0
{ | ||
"name": "stimulus_reflex", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"main": "./stimulus_reflex.js", | ||
"scripts": { | ||
"prettier-check": "yarn run prettier --check ./stimulus_reflex.js" | ||
}, | ||
"repository": { | ||
@@ -14,3 +17,6 @@ "type": "git", | ||
"cable_ready": ">= 4.0.3" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^1.18.2" | ||
} | ||
} |
@@ -41,3 +41,20 @@ import ActionCable from 'actioncable'; | ||
let target = args.shift(); | ||
controller.StimulusReflex.subscription.send({ target, args, url }); | ||
let attrs = Array.prototype.slice.call(this.element.attributes).reduce((memo, attr) => { | ||
memo[attr.name] = attr.value; | ||
return memo; | ||
}, {}); | ||
attrs.value = this.element.value; | ||
attrs.checked = !!this.element.checked; | ||
attrs.selected = !!this.element.selected; | ||
if (this.element.tagName.match(/select/i)) { | ||
if (this.element.multiple) { | ||
const checkedOptions = Array.prototype.slice.call(this.element.querySelectorAll('option:checked')); | ||
attrs.values = checkedOptions.map(o => o.value); | ||
} else if (this.element.selectedIndex > -1) { | ||
attrs.value = this.element.options[this.element.selectedIndex].value; | ||
} | ||
} | ||
controller.StimulusReflex.subscription.send({ target, args, attrs, url }); | ||
}, | ||
@@ -44,0 +61,0 @@ }); |
3326
71
1
2