2022-12-22 10:53:33 +00:00
|
|
|
<template>
|
2023-11-28 07:47:40 +00:00
|
|
|
<input-wrapper
|
2023-12-01 20:24:38 +00:00
|
|
|
v-bind="inputWrapperProps"
|
2023-11-28 07:47:40 +00:00
|
|
|
>
|
|
|
|
<template #label>
|
|
|
|
<slot name="label" />
|
|
|
|
</template>
|
2022-12-22 10:53:33 +00:00
|
|
|
|
|
|
|
<VueSignaturePad ref="signaturePad"
|
2023-11-28 08:09:02 +00:00
|
|
|
:class="[theme.default.input,{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }]"
|
|
|
|
height="150px"
|
2022-12-22 10:53:33 +00:00
|
|
|
:name="name"
|
|
|
|
:options="{ onEnd }"
|
|
|
|
/>
|
|
|
|
|
2023-11-28 08:24:57 +00:00
|
|
|
<template #bottom_after_help>
|
2022-12-22 10:53:33 +00:00
|
|
|
<small :class="theme.default.help">
|
|
|
|
<a :class="theme.default.help" href="#" @click.prevent="clear">Clear</a>
|
|
|
|
</small>
|
2023-11-28 07:47:40 +00:00
|
|
|
</template>
|
2023-12-01 20:24:38 +00:00
|
|
|
|
2023-11-28 07:47:40 +00:00
|
|
|
<template #error>
|
|
|
|
<slot name="error" />
|
|
|
|
</template>
|
|
|
|
</input-wrapper>
|
2022-12-22 10:53:33 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-11-28 07:47:40 +00:00
|
|
|
import { inputProps, useFormInput } from './useFormInput.js'
|
|
|
|
import InputWrapper from './components/InputWrapper.vue'
|
2023-11-28 08:09:02 +00:00
|
|
|
import { VueSignaturePad } from 'vue-signature-pad'
|
2022-12-22 10:53:33 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'SignatureInput',
|
2023-11-28 08:09:02 +00:00
|
|
|
components: { InputWrapper, VueSignaturePad },
|
2023-11-28 07:47:40 +00:00
|
|
|
|
|
|
|
props: {
|
2023-11-28 08:09:02 +00:00
|
|
|
...inputProps
|
2023-11-28 07:47:40 +00:00
|
|
|
},
|
2022-12-22 10:53:33 +00:00
|
|
|
|
2023-11-28 07:47:40 +00:00
|
|
|
setup (props, context) {
|
|
|
|
return {
|
2023-12-01 20:24:38 +00:00
|
|
|
...useFormInput(props, context)
|
2023-11-28 07:47:40 +00:00
|
|
|
}
|
|
|
|
},
|
2022-12-22 10:53:33 +00:00
|
|
|
|
|
|
|
methods: {
|
|
|
|
clear () {
|
|
|
|
this.$refs.signaturePad.clearSignature()
|
|
|
|
this.onEnd()
|
|
|
|
},
|
|
|
|
onEnd () {
|
2023-10-24 09:00:54 +00:00
|
|
|
if (this.disabled) {
|
2023-03-22 14:49:52 +00:00
|
|
|
this.$refs.signaturePad.clearSignature()
|
2023-10-24 09:00:54 +00:00
|
|
|
} else {
|
2023-03-22 14:49:52 +00:00
|
|
|
const { isEmpty, data } = this.$refs.signaturePad.saveSignature()
|
2023-10-24 09:00:54 +00:00
|
|
|
this.form[this.name] = (!isEmpty && data) ? data : null
|
2023-03-22 14:49:52 +00:00
|
|
|
}
|
2022-12-22 10:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|