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 4.0KB

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