Add form support to `RadioButton`

pull/6632/head
Mert Sincan 2024-10-18 16:55:57 +01:00
parent c806a8c749
commit 2a63b3fdce
3 changed files with 8 additions and 24 deletions

View File

@ -1,30 +1,13 @@
<script>
import BaseComponent from '@primevue/core/basecomponent';
import BaseInput from '@primevue/core/baseinput';
import RadioButtonStyle from 'primevue/radiobutton/style';
export default {
name: 'BaseRadioButton',
extends: BaseComponent,
extends: BaseInput,
props: {
value: null,
modelValue: null,
binary: Boolean,
name: {
type: String,
default: null
},
variant: {
type: String,
default: null
},
invalid: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
},
readonly: {
type: Boolean,
default: false

View File

@ -33,7 +33,7 @@ export default {
name: 'RadioButton',
extends: BaseRadioButton,
inheritAttrs: false,
emits: ['update:modelValue', 'change', 'focus', 'blur'],
emits: ['change', 'focus', 'blur'],
methods: {
getPTOptions(key) {
const _ptm = key === 'root' ? this.ptmi : this.ptm;
@ -49,7 +49,7 @@ export default {
if (!this.disabled && !this.readonly) {
const newModelValue = this.binary ? !this.checked : this.value;
this.$emit('update:modelValue', newModelValue);
this.updateValue(newModelValue, event);
this.$emit('change', event);
}
},
@ -58,11 +58,12 @@ export default {
},
onBlur(event) {
this.$emit('blur', event);
this.formField.onBlur?.(event);
}
},
computed: {
checked() {
return this.modelValue != null && (this.binary ? !!this.modelValue : equals(this.modelValue, this.value));
return this.d_value != null && (this.binary ? !!this.d_value : equals(this.d_value, this.value));
}
}
};

View File

@ -125,8 +125,8 @@ const classes = {
{
'p-radiobutton-checked': instance.checked,
'p-disabled': props.disabled,
'p-invalid': props.invalid,
'p-variant-filled': props.variant ? props.variant === 'filled' : instance.$primevue.config.inputStyle === 'filled' || instance.$primevue.config.inputVariant === 'filled'
'p-invalid': instance.$invalid,
'p-variant-filled': instance.$variant === 'filled'
}
],
box: 'p-radiobutton-box',