From 53a69ebd726f80d8dd8172b6581a209d6026f2de Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Wed, 25 Aug 2021 09:53:23 +0300 Subject: [PATCH] Fixed #1470 - Add trueValue-falseValue to InputSwitch --- api-generator/components/inputswitch.js | 12 ++++++++++++ src/components/inputswitch/InputSwitch.d.ts | 2 ++ src/components/inputswitch/InputSwitch.vue | 20 ++++++++++++++++---- src/views/inputswitch/InputSwitchDoc.vue | 12 ++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/api-generator/components/inputswitch.js b/api-generator/components/inputswitch.js index 3ec4eb3d0..ac794a9fa 100644 --- a/api-generator/components/inputswitch.js +++ b/api-generator/components/inputswitch.js @@ -16,6 +16,18 @@ const InputSwitchProps = [ type: "any", default: "null", description: "Inline of the component." + }, + { + name: "trueValue", + type: "any", + default: "true", + description: "Value in checked state." + }, + { + name: "falseValue", + type: "any", + default: "true", + description: "Value in unchecked state." } ]; diff --git a/src/components/inputswitch/InputSwitch.d.ts b/src/components/inputswitch/InputSwitch.d.ts index 35a5c7a9b..a39f0e324 100755 --- a/src/components/inputswitch/InputSwitch.d.ts +++ b/src/components/inputswitch/InputSwitch.d.ts @@ -2,6 +2,8 @@ interface InputSwitchProps { modelValue?: boolean; class?: string; style?: any; + trueValue?: any; + falseValue?: any; } declare class InputSwitch { diff --git a/src/components/inputswitch/InputSwitch.vue b/src/components/inputswitch/InputSwitch.vue index fc61eca96..f630ee273 100755 --- a/src/components/inputswitch/InputSwitch.vue +++ b/src/components/inputswitch/InputSwitch.vue @@ -16,7 +16,15 @@ export default { props: { modelValue: Boolean, class: null, - style: null + style: null, + trueValue: { + type: null, + default: true + }, + falseValue: { + type: null, + default: false + } }, data() { return { @@ -26,10 +34,11 @@ export default { methods: { onClick(event) { if (!this.$attrs.disabled) { + const newValue = this.checked ? this.falseValue : this.trueValue; this.$emit('click', event); - this.$emit('update:modelValue', !this.modelValue); + this.$emit('update:modelValue', newValue); this.$emit('change', event); - this.$emit('input', !this.modelValue); + this.$emit('input', newValue); this.$refs.input.focus(); } event.preventDefault(); @@ -48,11 +57,14 @@ export default { return [ 'p-inputswitch p-component', this.class, { - 'p-inputswitch-checked': this.modelValue, + 'p-inputswitch-checked': this.checked, 'p-disabled': this.$attrs.disabled, 'p-focus': this.focused } ]; + }, + checked() { + return this.modelValue === this.trueValue; } } } diff --git a/src/views/inputswitch/InputSwitchDoc.vue b/src/views/inputswitch/InputSwitchDoc.vue index 6da88832c..ce9e563fe 100755 --- a/src/views/inputswitch/InputSwitchDoc.vue +++ b/src/views/inputswitch/InputSwitchDoc.vue @@ -67,6 +67,18 @@ export default { string null Inline style of the component. + + + trueValue + any + null + Value in checked state. + + + falseValue + any + null + Value in unchecked state.