Fixed #1320 - Checkbox true-value / false-value does not work
parent
b13d8d517f
commit
3a854247be
|
@ -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."
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ interface CheckboxProps {
|
|||
binary?: boolean;
|
||||
class?: string;
|
||||
style?: any;
|
||||
trueValue?: any;
|
||||
falseValue?: any;
|
||||
}
|
||||
|
||||
declare class Checkbox {
|
||||
|
|
|
@ -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}];
|
||||
|
|
|
@ -79,6 +79,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>
|
||||
|
|
Loading…
Reference in New Issue