From d24f50824831f4b6541693716f0aa09942abcbf7 Mon Sep 17 00:00:00 2001 From: Rijn Date: Wed, 9 Aug 2017 10:07:38 -0500 Subject: [PATCH] Support trueValue and falseValue for radio --- examples/routers/radio.vue | 9 ++++++--- src/components/radio/radio.vue | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/examples/routers/radio.vue b/examples/routers/radio.vue index 53df9a4..a495fcf 100644 --- a/examples/routers/radio.vue +++ b/examples/routers/radio.vue @@ -1,11 +1,13 @@ @@ -16,7 +18,8 @@ date: { sex: 'male' }, - show: false + show: false, + testValue: null } }, methods: { diff --git a/src/components/radio/radio.vue b/src/components/radio/radio.vue index d7513da..32a6e47 100644 --- a/src/components/radio/radio.vue +++ b/src/components/radio/radio.vue @@ -22,7 +22,15 @@ mixins: [ Emitter ], props: { value: { - type: Boolean, + type: [String, Number, Boolean], + default: false + }, + trueValue: { + type: [String, Number, Boolean], + default: true + }, + falseValue: { + type: [String, Number, Boolean], default: false }, label: { @@ -83,7 +91,9 @@ const checked = event.target.checked; this.currentValue = checked; - this.$emit('input', checked); + + let value = checked ? this.trueValue : this.falseValue; + this.$emit('input', value); if (this.group && this.label !== undefined) { this.parent.change({ @@ -92,16 +102,19 @@ }); } if (!this.group) { - this.$emit('on-change', checked); - this.dispatch('FormItem', 'on-form-change', checked); + this.$emit('on-change', value); + this.dispatch('FormItem', 'on-form-change', value); } }, updateValue () { - this.currentValue = this.value; + this.currentValue = this.value === this.trueValue; } }, watch: { - value () { + value (val) { + if (val !== this.trueValue && val !== this.falseValue) { + throw 'Value should be trueValue or falseValue.'; + } this.updateValue(); } } -- libgit2 0.21.4