Skip to content

Commit

Permalink
Fixed #1470 - Add trueValue-falseValue to InputSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Aug 25, 2021
1 parent 3a85424 commit 53a69eb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
12 changes: 12 additions & 0 deletions api-generator/components/inputswitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
];

Expand Down
2 changes: 2 additions & 0 deletions src/components/inputswitch/InputSwitch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ interface InputSwitchProps {
modelValue?: boolean;
class?: string;
style?: any;
trueValue?: any;
falseValue?: any;
}

declare class InputSwitch {
Expand Down
20 changes: 16 additions & 4 deletions src/components/inputswitch/InputSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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;
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/views/inputswitch/InputSwitchDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ export default {
<td>string</td>
<td>null</td>
<td>Inline style of the component.</td>
</tr>
<tr>
<td>trueValue</td>
<td>any</td>
<td>null</td>
<td>Value in checked state.</td>
</tr>
<tr>
<td>falseValue</td>
<td>any</td>
<td>null</td>
<td>Value in unchecked state.</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 53a69eb

Please sign in to comment.