fantasia-archive/src/components/fields/Field_Text.vue

151 lines
3.7 KiB
Vue
Raw Normal View History

2021-01-31 02:43:13 +13:00
<template>
<div>
<div class="flex justify-start items-center text-weight-bolder q-mb-sm q-mt-md">
<q-icon v-if="inputIcon" :name="inputIcon" :size="inputIcon.includes('fas')? '15px': '20px'" class="q-mr-sm"/>
2021-01-31 02:43:13 +13:00
{{inputDataBluePrint.name}}
2021-03-18 10:26:08 +13:00
<q-icon v-if="toolTip && !disableDocumentToolTips" name="mdi-help-circle" size="16px" class="q-ml-md">
2021-02-26 14:50:46 +13:00
<q-tooltip :delay="500">
2021-02-21 01:06:21 +13:00
<span v-html="toolTip"/>
</q-tooltip>
</q-icon>
2021-01-31 02:43:13 +13:00
</div>
<q-list
v-if="!editMode"
2021-03-08 11:07:40 +13:00
class="fieldText_list"
2021-01-31 02:43:13 +13:00
dense>
<q-item>
<q-item-section>
2021-03-08 11:07:40 +13:00
<span class="text-weight-medium">
2021-01-31 02:43:13 +13:00
{{localInput}}
2021-03-08 11:07:40 +13:00
</span>
2021-01-31 02:43:13 +13:00
</q-item-section>
</q-item>
</q-list>
<q-input
v-if="editMode"
v-model="localInput"
2021-04-28 13:06:41 +12:00
@keydown="processInput"
2021-03-18 10:26:08 +13:00
:outlined="!isDarkMode"
:filled="isDarkMode"
2021-01-31 02:43:13 +13:00
dense
2021-02-21 01:06:21 +13:00
:ref="`textField${this.inputDataBluePrint.id}`"
2021-01-31 02:43:13 +13:00
>
2021-02-09 15:21:48 +13:00
<template v-slot:append v-if="isNew && !changedInput && localInput.length > 0">
2021-01-31 02:43:13 +13:00
<q-icon name="close" @click="deletePlaceholder()" class="cursor-pointer" />
</template>
</q-input>
2021-02-09 15:21:48 +13:00
<div class="separatorWrapper">
2021-03-08 11:07:40 +13:00
<q-separator color="grey q-mt-md" />
2021-02-09 15:21:48 +13:00
</div>
2021-01-31 02:43:13 +13:00
</div>
</template>
<script lang="ts">
import { Component, Emit, Prop, Watch } from "vue-property-decorator"
2021-04-04 09:25:27 +12:00
import FieldBase from "src/components/fields/_FieldBase"
2021-01-31 02:43:13 +13:00
@Component({
components: { }
})
2021-04-04 09:25:27 +12:00
export default class Field_Text extends FieldBase {
/****************************************************************/
// BASIC FIELD DATA
/****************************************************************/
/**
* Already existing value in the input field (IF one is there right now)
*/
2021-01-31 02:43:13 +13:00
@Prop({ default: "" }) readonly inputDataValue!: string
2021-04-04 09:25:27 +12:00
/**
* Determines if the parent document is new or not
*/
2021-01-31 02:43:13 +13:00
@Prop() readonly isNew!: boolean
2021-04-04 09:25:27 +12:00
/****************************************************************/
// INPUT HANDLING
/****************************************************************/
2021-03-18 10:26:08 +13:00
2021-04-04 09:25:27 +12:00
/**
* Watch changes to the prefilled data already existing in the field and update local input accordingly
*/
@Watch("inputDataValue", { deep: true, immediate: true })
reactToInputChanges () {
this.localInput = this.inputDataValue
2021-03-18 10:26:08 +13:00
}
2021-04-04 09:25:27 +12:00
/**
* Determines if the input has any changes on it or not
*/
2021-01-31 02:43:13 +13:00
changedInput = false
2021-04-04 09:25:27 +12:00
/**
* Model for the local input
*/
2021-01-31 02:43:13 +13:00
localInput = ""
2021-04-04 09:25:27 +12:00
/**
* Deletes the placeholder value in the input field
*/
2021-01-31 02:43:13 +13:00
deletePlaceholder () {
this.localInput = ""
2021-04-28 13:06:41 +12:00
this.processInput()
2021-01-31 02:43:13 +13:00
}
2021-04-04 09:25:27 +12:00
/**
* Observe change on the edit mode and in case this field is "name", auto-select it as first field
*/
2021-02-21 01:06:21 +13:00
@Watch("editMode", { immediate: true })
checkForNameFields () {
if (this.inputDataBluePrint?.id === "name" && this.editMode === true) {
this.$nextTick(function () {
/*eslint-disable */
// @ts-ignore
this.$refs[`textField${this.inputDataBluePrint.id}`].focus()
if(this.isNew && !this.changedInput && this.localInput.length > 0){
// @ts-ignore
this.$refs[`textField${this.inputDataBluePrint.id}`].select()
}
/* eslint-enable */
})
}
}
2021-04-28 13:06:41 +12:00
/**
* Debounce timer to prevent buggy input sync
*/
pullTimer = null as any
processInput () {
clearTimeout(this.pullTimer)
this.pullTimer = setTimeout(() => {
this.signalInput()
}, 500)
}
2021-04-04 09:25:27 +12:00
/**
* Signals the input change to the document body parent component
*/
@Emit()
signalInput () {
this.changedInput = true
return this.localInput.trim()
2021-01-31 02:43:13 +13:00
}
}
</script>
2021-03-08 11:07:40 +13:00
<style lang='scss'>
.fieldText_list {
.q-item {
padding-right: 10px;
padding-left: 10px;
}
}
</style>