prefill typed signature and initials from name
This commit is contained in:
@@ -421,6 +421,7 @@
|
|||||||
v-model="values[currentField.uuid]"
|
v-model="values[currentField.uuid]"
|
||||||
:field="currentField"
|
:field="currentField"
|
||||||
:dry-run="dryRun"
|
:dry-run="dryRun"
|
||||||
|
:submitter="submitter"
|
||||||
:previous-value="previousInitialsValue"
|
:previous-value="previousInitialsValue"
|
||||||
:attachments-index="attachmentsIndex"
|
:attachments-index="attachmentsIndex"
|
||||||
:show-field-names="showFieldNames"
|
:show-field-names="showFieldNames"
|
||||||
|
|||||||
@@ -175,6 +175,10 @@ export default {
|
|||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
|
submitter: {
|
||||||
|
type: Object,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
dryRun: {
|
dryRun: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
@@ -257,6 +261,14 @@ export default {
|
|||||||
|
|
||||||
this.$refs.canvas.getContext('2d').scale(scale, scale)
|
this.$refs.canvas.getContext('2d').scale(scale, scale)
|
||||||
|
|
||||||
|
if (!this.isDrawInitials) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.textInput) {
|
||||||
|
this.initTextInitial()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.intersectionObserver?.disconnect()
|
this.intersectionObserver?.disconnect()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -332,12 +344,25 @@ export default {
|
|||||||
|
|
||||||
if (!this.isDrawInitials) {
|
if (!this.isDrawInitials) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.textInput.focus()
|
if (this.$refs.textInput) {
|
||||||
|
this.$refs.textInput.focus()
|
||||||
|
|
||||||
this.$emit('start')
|
this.initTextInitial()
|
||||||
|
|
||||||
|
this.$emit('start')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
initTextInitial () {
|
||||||
|
if (this.submitter.name) {
|
||||||
|
this.$refs.textInput.value = this.submitter.name.trim().split(/\s+/).filter(Boolean).slice(0, 2).map((part) => part[0]?.toUpperCase() || '').join('')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.$refs.textInput.value) {
|
||||||
|
this.updateWrittenInitials({ target: this.$refs.textInput })
|
||||||
|
}
|
||||||
|
},
|
||||||
async submit () {
|
async submit () {
|
||||||
if (this.modelValue || this.computedPreviousValue) {
|
if (this.modelValue || this.computedPreviousValue) {
|
||||||
if (this.computedPreviousValue) {
|
if (this.computedPreviousValue) {
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ import FileDropzone from './dropzone'
|
|||||||
import MarkdownContent from './markdown_content'
|
import MarkdownContent from './markdown_content'
|
||||||
import { v4 } from 'uuid'
|
import { v4 } from 'uuid'
|
||||||
|
|
||||||
let isFontLoaded = false
|
let fontLoadPromise = null
|
||||||
|
|
||||||
const scale = 3
|
const scale = 3
|
||||||
|
|
||||||
@@ -482,6 +482,14 @@ export default {
|
|||||||
if (entry.isIntersecting) {
|
if (entry.isIntersecting) {
|
||||||
this.setCanvasSize()
|
this.setCanvasSize()
|
||||||
|
|
||||||
|
if (this.isTextSignature) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
if (this.$refs.textInput) {
|
||||||
|
this.initTypedSignature()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.intersectionObserver?.disconnect()
|
this.intersectionObserver?.disconnect()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -504,6 +512,10 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.resizeObserver.observe(this.$refs.canvas.parentNode)
|
this.resizeObserver.observe(this.$refs.canvas.parentNode)
|
||||||
|
|
||||||
|
if (this.isTextSignature) {
|
||||||
|
this.loadFont()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeUnmount () {
|
beforeUnmount () {
|
||||||
@@ -541,7 +553,7 @@ export default {
|
|||||||
|
|
||||||
this.pad.fromData(scaledData)
|
this.pad.fromData(scaledData)
|
||||||
} else if (this.isTextSignature && this.$refs.textInput) {
|
} else if (this.isTextSignature && this.$refs.textInput) {
|
||||||
this.updateWrittenSignature({ target: { value: this.$refs.textInput.value } })
|
this.updateWrittenSignature({ target: this.$refs.textInput })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
remove () {
|
remove () {
|
||||||
@@ -551,17 +563,17 @@ export default {
|
|||||||
this.isSignatureStarted = false
|
this.isSignatureStarted = false
|
||||||
},
|
},
|
||||||
loadFont () {
|
loadFont () {
|
||||||
if (!isFontLoaded) {
|
if (!fontLoadPromise) {
|
||||||
const font = new FontFace('Dancing Script', `url(${this.baseUrl}/fonts/DancingScript-Regular.otf) format("opentype")`)
|
const font = new FontFace('Dancing Script', `url(${this.baseUrl}/fonts/DancingScript-Regular.otf) format("opentype")`)
|
||||||
|
|
||||||
font.load().then((loadedFont) => {
|
fontLoadPromise = font.load().then((loadedFont) => {
|
||||||
document.fonts.add(loadedFont)
|
document.fonts.add(loadedFont)
|
||||||
|
|
||||||
isFontLoaded = true
|
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error('Font loading failed:', error)
|
console.error('Font loading failed:', error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fontLoadPromise
|
||||||
},
|
},
|
||||||
showQr () {
|
showQr () {
|
||||||
this.isShowQr = true
|
this.isShowQr = true
|
||||||
@@ -661,14 +673,27 @@ export default {
|
|||||||
|
|
||||||
if (this.isTextSignature) {
|
if (this.isTextSignature) {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.$refs.textInput.focus()
|
if (this.$refs.textInput) {
|
||||||
|
this.$refs.textInput.focus()
|
||||||
|
|
||||||
this.loadFont()
|
this.initTypedSignature()
|
||||||
|
|
||||||
this.$emit('start')
|
this.$emit('start')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async initTypedSignature () {
|
||||||
|
if (this.submitter.name) {
|
||||||
|
this.$refs.textInput.value = this.submitter.name
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.loadFont()
|
||||||
|
|
||||||
|
if (this.$refs.textInput.value) {
|
||||||
|
this.updateWrittenSignature({ target: this.$refs.textInput })
|
||||||
|
}
|
||||||
|
},
|
||||||
drawImage (event) {
|
drawImage (event) {
|
||||||
this.remove()
|
this.remove()
|
||||||
this.clear()
|
this.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user