Add form support to `ToggleSwitch`

pull/6632/head
Mert Sincan 2024-10-18 17:27:07 +01:00
parent 044eacead1
commit c7f6e25d74
3 changed files with 7 additions and 15 deletions

View File

@ -1,12 +1,11 @@
<script>
import BaseComponent from '@primevue/core/basecomponent';
import BaseEditableHolder from '@primevue/core/baseeditableholder';
import ToggleButtonStyle from 'primevue/togglebutton/style';
export default {
name: 'BaseToggleButton',
extends: BaseComponent,
extends: BaseEditableHolder,
props: {
modelValue: Boolean,
onIcon: String,
offIcon: String,
onLabel: {
@ -21,14 +20,6 @@ export default {
type: String,
default: 'left'
},
invalid: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
},
readonly: {
type: Boolean,
default: false

View File

@ -34,7 +34,7 @@ export default {
name: 'ToggleSwitch',
extends: BaseToggleSwitch,
inheritAttrs: false,
emits: ['update:modelValue', 'change', 'focus', 'blur'],
emits: ['change', 'focus', 'blur'],
methods: {
getPTOptions(key) {
const _ptm = key === 'root' ? this.ptmi : this.ptm;
@ -50,7 +50,7 @@ export default {
if (!this.disabled && !this.readonly) {
const newValue = this.checked ? this.falseValue : this.trueValue;
this.$emit('update:modelValue', newValue);
this.updateValue(newValue, event);
this.$emit('change', event);
}
},
@ -59,11 +59,12 @@ export default {
},
onBlur(event) {
this.$emit('blur', event);
this.formField.onBlur?.(event);
}
},
computed: {
checked() {
return this.modelValue === this.trueValue;
return this.d_value === this.trueValue;
}
}
};

View File

@ -120,7 +120,7 @@ const classes = {
{
'p-toggleswitch-checked': instance.checked,
'p-disabled': props.disabled,
'p-invalid': props.invalid
'p-invalid': instance.$invalid
}
],
input: 'p-toggleswitch-input',