Skip to content

Commit

Permalink
Add number formatting to formatted-values display (directus#6186)
Browse files Browse the repository at this point in the history
* Render number values as formatted numbers

* Allow for 0 in formatted-values display

* Use isNil for empty check
  • Loading branch information
rijkvanzanten authored Jun 10, 2021
1 parent 34d0d2d commit 976baa7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/src/displays/formatted-value/formatted-value.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<value-null v-if="!displayValue" />
<value-null v-if="displayValue === null || displayValue === undefined" />

<span v-else class="display-formatted-text" :class="[{ bold }, font]" :style="{ color }">
{{ displayValue }}
Expand All @@ -10,6 +10,8 @@
import { defineComponent, computed } from 'vue';
import formatTitle from '@directus/format-title';
import { decode } from 'html-entities';
import { useI18n } from 'vue-i18n';
import { isNil } from 'lodash';
export default defineComponent({
props: {
Expand All @@ -36,8 +38,15 @@ export default defineComponent({
},
},
setup(props) {
const { n } = useI18n();
const displayValue = computed(() => {
if (!props.value) return null;
if (isNil(props.value) || props.value === '') return null;
if (typeof props.value === 'number') {
return n(props.value);
}
let value = String(props.value);
// Strip out all HTML tags
Expand Down

0 comments on commit 976baa7

Please sign in to comment.