fix: Render checkbox if string value passed (#3453)

This commit is contained in:
Muhsin Keloth 2021-11-24 11:02:45 +05:30 committed by GitHub
parent da8f9d0337
commit 00143f7ee5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,7 +66,7 @@
{{ value || '---' }} {{ value || '---' }}
</a> </a>
<p v-else class="value"> <p v-else class="value">
{{ formattedValue || '---' }} {{ displayValue || '---' }}
</p> </p>
<div class="action-buttons__wrap"> <div class="action-buttons__wrap">
<woot-button <woot-button
@ -138,10 +138,7 @@ export default {
data() { data() {
return { return {
isEditing: false, isEditing: false,
editedValue: editedValue: null,
this.attributeType === 'date'
? format(new Date(this.value || new Date()), DATE_FORMAT)
: this.value,
}; };
}, },
validations() { validations() {
@ -156,6 +153,15 @@ export default {
}, },
computed: { computed: {
formattedValue() {
if (this.isAttributeTypeDate) {
return format(new Date(this.value || new Date()), DATE_FORMAT);
}
if (this.isAttributeTypeCheckbox) {
return this.value === 'false' ? false : this.value;
}
return this.value;
},
listOptions() { listOptions() {
return this.values.map((value, index) => ({ return this.values.map((value, index) => ({
id: index + 1, id: index + 1,
@ -175,6 +181,9 @@ export default {
isAttributeTypeLink() { isAttributeTypeLink() {
return this.attributeType === 'link'; return this.attributeType === 'link';
}, },
isAttributeTypeDate() {
return this.attributeType === 'date';
},
notAttributeTypeCheckboxAndList() { notAttributeTypeCheckboxAndList() {
return !this.isAttributeTypeCheckbox && !this.isAttributeTypeList; return !this.isAttributeTypeCheckbox && !this.isAttributeTypeList;
}, },
@ -190,7 +199,7 @@ export default {
} }
return this.$t('CUSTOM_ATTRIBUTES.VALIDATIONS.REQUIRED'); return this.$t('CUSTOM_ATTRIBUTES.VALIDATIONS.REQUIRED');
}, },
formattedValue() { displayValue() {
if (this.attributeType === 'date') { if (this.attributeType === 'date') {
return format(new Date(this.editedValue), 'dd-MM-yyyy'); return format(new Date(this.editedValue), 'dd-MM-yyyy');
} }
@ -198,6 +207,7 @@ export default {
}, },
}, },
mounted() { mounted() {
this.editedValue = this.formattedValue;
bus.$on(BUS_EVENTS.FOCUS_CUSTOM_ATTRIBUTE, focusAttributeKey => { bus.$on(BUS_EVENTS.FOCUS_CUSTOM_ATTRIBUTE, focusAttributeKey => {
if (this.attributeKey === focusAttributeKey) { if (this.attributeKey === focusAttributeKey) {
this.onEdit(); this.onEdit();