This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/radio-button.js
2020-03-12 13:29:55 -04:00

33 lines
663 B
JavaScript

import discourseComputed from "discourse-common/utils/decorators";
import Component from "@ember/component";
export default Component.extend({
tagName: "input",
type: "radio",
attributeBindings: [
"name",
"type",
"value",
"checked:checked",
"disabled:disabled"
],
click() {
const value = $(this.element).val();
if (this.onChange) {
this.onChange(value);
} else {
if (this.selection === value) {
this.set("selection", undefined);
}
this.set("selection", value);
}
},
@discourseComputed("value", "selection")
checked(value, selection) {
return value === selection;
}
});