Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VRadioGroup.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Styles
  2. import '../../../src/stylus/components/_selection-controls.styl';
  3. import '../../../src/stylus/components/_radio-group.styl';
  4. // Components
  5. import VInput from '../VInput';
  6. // Mixins
  7. import Comparable from '../../mixins/comparable';
  8. import { provide as RegistrableProvide } from '../../mixins/registrable';
  9. /* @vue/component */
  10. export default VInput.extend({
  11. name: 'v-radio-group',
  12. mixins: [Comparable, RegistrableProvide('radio')],
  13. model: {
  14. prop: 'value',
  15. event: 'change'
  16. },
  17. provide: function provide() {
  18. return {
  19. radio: this
  20. };
  21. },
  22. props: {
  23. column: {
  24. type: Boolean,
  25. default: true
  26. },
  27. height: {
  28. type: [Number, String],
  29. default: 'auto'
  30. },
  31. mandatory: {
  32. type: Boolean,
  33. default: true
  34. },
  35. name: String,
  36. row: Boolean,
  37. // If no value set on VRadio
  38. // will match valueComparator
  39. // force default to null
  40. value: {
  41. default: null
  42. }
  43. },
  44. data: function data() {
  45. return {
  46. internalTabIndex: -1,
  47. radios: []
  48. };
  49. },
  50. computed: {
  51. classes: function classes() {
  52. return {
  53. 'v-input--selection-controls v-input--radio-group': true,
  54. 'v-input--radio-group--column': this.column && !this.row,
  55. 'v-input--radio-group--row': this.row
  56. };
  57. }
  58. },
  59. watch: {
  60. hasError: 'setErrorState',
  61. internalValue: 'setActiveRadio'
  62. },
  63. mounted: function mounted() {
  64. this.setErrorState(this.hasError);
  65. this.setActiveRadio();
  66. },
  67. methods: {
  68. genDefaultSlot: function genDefaultSlot() {
  69. return this.$createElement('div', {
  70. staticClass: 'v-input--radio-group__input',
  71. attrs: {
  72. role: 'radiogroup'
  73. }
  74. }, VInput.options.methods.genDefaultSlot.call(this));
  75. },
  76. onRadioChange: function onRadioChange(value) {
  77. if (this.disabled) return;
  78. this.hasInput = true;
  79. this.internalValue = value;
  80. this.setActiveRadio();
  81. this.$nextTick(this.validate);
  82. },
  83. onRadioBlur: function onRadioBlur(e) {
  84. if (!e.relatedTarget || !e.relatedTarget.classList.contains('v-radio')) {
  85. this.hasInput = true;
  86. this.$emit('blur', e);
  87. }
  88. },
  89. register: function register(radio) {
  90. radio.isActive = this.valueComparator(this.internalValue, radio.value);
  91. radio.$on('change', this.onRadioChange);
  92. radio.$on('blur', this.onRadioBlur);
  93. this.radios.push(radio);
  94. },
  95. setErrorState: function setErrorState(val) {
  96. for (var index = this.radios.length; --index >= 0;) {
  97. this.radios[index].parentError = val;
  98. }
  99. },
  100. setActiveRadio: function setActiveRadio() {
  101. for (var index = this.radios.length; --index >= 0;) {
  102. var radio = this.radios[index];
  103. radio.isActive = this.valueComparator(this.internalValue, radio.value);
  104. }
  105. },
  106. unregister: function unregister(radio) {
  107. radio.$off('change', this.onRadioChange);
  108. radio.$off('blur', this.onRadioBlur);
  109. var index = this.radios.findIndex(function (r) {
  110. return r === radio;
  111. });
  112. /* istanbul ignore else */
  113. if (index > -1) this.radios.splice(index, 1);
  114. }
  115. }
  116. });
  117. //# sourceMappingURL=VRadioGroup.js.map