Add form support to `ToggleSwitch`
parent
044eacead1
commit
c7f6e25d74
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue