diff --git a/api-generator/components/checkbox.js b/api-generator/components/checkbox.js index 105f9a4ff..d0ee781c1 100644 --- a/api-generator/components/checkbox.js +++ b/api-generator/components/checkbox.js @@ -28,6 +28,18 @@ const CheckboxProps = [ 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/checkbox/Checkbox.d.ts b/src/components/checkbox/Checkbox.d.ts index d7ec4be27..c4a974de6 100755 --- a/src/components/checkbox/Checkbox.d.ts +++ b/src/components/checkbox/Checkbox.d.ts @@ -4,6 +4,8 @@ interface CheckboxProps { binary?: boolean; class?: string; style?: any; + trueValue?: any; + falseValue?: any; } declare class Checkbox { diff --git a/src/components/checkbox/Checkbox.vue b/src/components/checkbox/Checkbox.vue index 718eff703..7d9098874 100755 --- a/src/components/checkbox/Checkbox.vue +++ b/src/components/checkbox/Checkbox.vue @@ -21,7 +21,15 @@ export default { modelValue: null, binary: Boolean, class: null, - style: null + style: null, + trueValue: { + type: null, + default: true + }, + falseValue: { + type: null, + default: false + } }, data() { return { @@ -34,7 +42,7 @@ export default { let newModelValue; if (this.binary) { - newModelValue = !this.modelValue; + newModelValue = this.checked ? this.falseValue : this.trueValue; } else { if (this.checked) @@ -58,7 +66,7 @@ export default { }, computed: { checked() { - return this.binary ? this.modelValue : ObjectUtils.contains(this.value, this.modelValue); + return this.binary ? this.modelValue === this.trueValue : ObjectUtils.contains(this.value, this.modelValue); }, containerClass() { return ['p-checkbox p-component', this.class, {'p-checkbox-checked': this.checked, 'p-checkbox-disabled': this.$attrs.disabled, 'p-checkbox-focused': this.focused}]; diff --git a/src/views/checkbox/CheckboxDoc.vue b/src/views/checkbox/CheckboxDoc.vue index f9a8292ab..d7d11f6c7 100755 --- a/src/views/checkbox/CheckboxDoc.vue +++ b/src/views/checkbox/CheckboxDoc.vue @@ -79,6 +79,18 @@ export default { string null Inline style of the component. + + + trueValue + any + null + Value in checked state. + + + falseValue + any + null + Value in unchecked state.