| <template> |
| <Alert |
| v-if="descriptionToUse !== '' || $slots.default !== undefined" |
| type="light" |
| class="lh-2" |
| extraClasses="p-0 m-0" |
| style="padding: 0; margin: 0; line-height: 1.1em; margin-top: 4px" |
| > |
| <small> |
| <slot></slot> |
| <span v-if="$slots.default !== undefined"> </span> |
| <span |
| v-if="descriptionToUse !== ''" |
| v-html="descriptionToUse" |
| ></span> |
| </small> |
| </Alert> |
| </template> |
|
|
| <script lang="ts"> |
| import { Options, Vue } from "vue-class-component"; |
| import Alert from "@/UI/Layout/Alert.vue"; |
| import { Prop, Watch } from "vue-property-decorator"; |
| import { isSentence } from "@/Core/Utils/StringUtils"; |
| |
| |
| |
| |
| @Options({ |
| components: { |
| Alert, |
| }, |
| }) |
| export default class FormElementDescription extends Vue { |
| |
| |
| @Prop({}) description!: string; |
| @Prop({ default: "" }) warning!: string; |
| @Prop({ default: true }) validate!: boolean; |
| |
| |
| |
| |
| |
| |
| @Watch("description") |
| onDescriptionChanged(newVal: string) { |
| if (this.validate && !isSentence(newVal)) { |
| const msg = |
| "FormElementDescription: description must be a sentence (start with capital letter, end with punctuation): " + |
| newVal; |
| console.error(msg); |
| throw new Error(msg); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| get descriptionToUse(): string { |
| let desc = this.description; |
| |
| if (desc === undefined) desc = ""; |
| |
| if (this.warning !== "") { |
| desc = `${desc} <span class="text-danger">${this.warning}</span>`; |
| } |
| return desc; |
| } |
| |
| |
| |
| |
| mounted() { |
| this.onDescriptionChanged(this.description); |
| } |
| } |
| </script> |
|
|
| |
|
|
| <style lang="scss" scoped></style> |
|
|