Add form support to `ToggleSwitch`
parent
044eacead1
commit
c7f6e25d74
|
@ -1,12 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
import BaseComponent from '@primevue/core/basecomponent';
|
import BaseEditableHolder from '@primevue/core/baseeditableholder';
|
||||||
import ToggleButtonStyle from 'primevue/togglebutton/style';
|
import ToggleButtonStyle from 'primevue/togglebutton/style';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BaseToggleButton',
|
name: 'BaseToggleButton',
|
||||||
extends: BaseComponent,
|
extends: BaseEditableHolder,
|
||||||
props: {
|
props: {
|
||||||
modelValue: Boolean,
|
|
||||||
onIcon: String,
|
onIcon: String,
|
||||||
offIcon: String,
|
offIcon: String,
|
||||||
onLabel: {
|
onLabel: {
|
||||||
|
@ -21,14 +20,6 @@ export default {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'left'
|
default: 'left'
|
||||||
},
|
},
|
||||||
invalid: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
disabled: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
readonly: {
|
readonly: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
|
|
@ -34,7 +34,7 @@ export default {
|
||||||
name: 'ToggleSwitch',
|
name: 'ToggleSwitch',
|
||||||
extends: BaseToggleSwitch,
|
extends: BaseToggleSwitch,
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
emits: ['change', 'focus', 'blur'],
|
||||||
methods: {
|
methods: {
|
||||||
getPTOptions(key) {
|
getPTOptions(key) {
|
||||||
const _ptm = key === 'root' ? this.ptmi : this.ptm;
|
const _ptm = key === 'root' ? this.ptmi : this.ptm;
|
||||||
|
@ -50,7 +50,7 @@ export default {
|
||||||
if (!this.disabled && !this.readonly) {
|
if (!this.disabled && !this.readonly) {
|
||||||
const newValue = this.checked ? this.falseValue : this.trueValue;
|
const newValue = this.checked ? this.falseValue : this.trueValue;
|
||||||
|
|
||||||
this.$emit('update:modelValue', newValue);
|
this.updateValue(newValue, event);
|
||||||
this.$emit('change', event);
|
this.$emit('change', event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -59,11 +59,12 @@ export default {
|
||||||
},
|
},
|
||||||
onBlur(event) {
|
onBlur(event) {
|
||||||
this.$emit('blur', event);
|
this.$emit('blur', event);
|
||||||
|
this.formField.onBlur?.(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
checked() {
|
checked() {
|
||||||
return this.modelValue === this.trueValue;
|
return this.d_value === this.trueValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -120,7 +120,7 @@ const classes = {
|
||||||
{
|
{
|
||||||
'p-toggleswitch-checked': instance.checked,
|
'p-toggleswitch-checked': instance.checked,
|
||||||
'p-disabled': props.disabled,
|
'p-disabled': props.disabled,
|
||||||
'p-invalid': props.invalid
|
'p-invalid': instance.$invalid
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
input: 'p-toggleswitch-input',
|
input: 'p-toggleswitch-input',
|
||||||
|
|
Loading…
Reference in New Issue