2022-09-20 19:59:52 +00:00
|
|
|
<template>
|
2023-10-24 09:00:54 +00:00
|
|
|
<input-wrapper
|
2023-12-01 20:24:38 +00:00
|
|
|
v-bind="inputWrapperProps"
|
2023-10-24 09:00:54 +00:00
|
|
|
>
|
|
|
|
<template #label>
|
|
|
|
<slot name="label" />
|
|
|
|
</template>
|
|
|
|
|
2023-12-01 20:24:38 +00:00
|
|
|
<input :id="id?id:name" v-model="compVal" :disabled="disabled?true:null"
|
2022-09-20 19:59:52 +00:00
|
|
|
:type="nativeType"
|
2023-05-19 13:56:28 +00:00
|
|
|
:pattern="pattern"
|
2022-09-20 19:59:52 +00:00
|
|
|
:style="inputStyle"
|
2023-10-19 08:46:04 +00:00
|
|
|
:class="[theme.default.input, { '!ring-red-500 !ring-2': hasError, '!cursor-not-allowed !bg-gray-200': disabled }]"
|
2022-09-20 19:59:52 +00:00
|
|
|
:name="name" :accept="accept"
|
|
|
|
:placeholder="placeholder" :min="min" :max="max" :maxlength="maxCharLimit"
|
|
|
|
@change="onChange" @keydown.enter.prevent="onEnterPress"
|
|
|
|
>
|
2023-10-24 09:00:54 +00:00
|
|
|
|
2023-10-28 10:17:50 +00:00
|
|
|
<template v-if="maxCharLimit && showCharLimit" #bottom_after_help>
|
|
|
|
<small :class="theme.default.help">
|
2023-12-01 20:24:38 +00:00
|
|
|
{{ charCount }}/{{ maxCharLimit }}
|
2023-10-28 10:17:50 +00:00
|
|
|
</small>
|
|
|
|
</template>
|
2023-10-24 09:00:54 +00:00
|
|
|
|
|
|
|
<template #error>
|
|
|
|
<slot name="error" />
|
|
|
|
</template>
|
|
|
|
</input-wrapper>
|
2022-09-20 19:59:52 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-10-19 08:46:04 +00:00
|
|
|
import { inputProps, useFormInput } from './useFormInput.js'
|
2023-10-24 09:00:54 +00:00
|
|
|
import InputWrapper from './components/InputWrapper.vue'
|
2023-10-19 08:46:04 +00:00
|
|
|
|
2022-09-20 19:59:52 +00:00
|
|
|
export default {
|
|
|
|
name: 'TextInput',
|
2023-10-27 09:58:01 +00:00
|
|
|
components: { InputWrapper },
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
props: {
|
2023-10-19 08:46:04 +00:00
|
|
|
...inputProps,
|
2022-09-20 19:59:52 +00:00
|
|
|
nativeType: { type: String, default: 'text' },
|
|
|
|
accept: { type: String, default: null },
|
|
|
|
min: { type: Number, required: false, default: null },
|
|
|
|
max: { type: Number, required: false, default: null },
|
|
|
|
maxCharLimit: { type: Number, required: false, default: null },
|
|
|
|
showCharLimit: { type: Boolean, required: false, default: false },
|
2023-05-19 13:56:28 +00:00
|
|
|
pattern: { type: String, default: null }
|
2022-09-20 19:59:52 +00:00
|
|
|
},
|
|
|
|
|
2023-10-24 09:00:54 +00:00
|
|
|
setup (props, context) {
|
2023-10-19 08:46:04 +00:00
|
|
|
const onChange = (event) => {
|
|
|
|
if (props.nativeType !== 'file') return
|
2022-09-20 19:59:52 +00:00
|
|
|
|
|
|
|
const file = event.target.files[0]
|
2023-10-19 08:46:04 +00:00
|
|
|
// eslint-disable-next-line vue/no-mutating-props
|
|
|
|
props.form[props.name] = file
|
|
|
|
}
|
|
|
|
|
|
|
|
const onEnterPress = (event) => {
|
2022-09-20 19:59:52 +00:00
|
|
|
event.preventDefault()
|
|
|
|
return false
|
|
|
|
}
|
2023-10-19 08:46:04 +00:00
|
|
|
|
|
|
|
return {
|
2023-12-01 20:24:38 +00:00
|
|
|
...useFormInput(props, context, props.nativeType === 'file' ? 'file-' : null),
|
|
|
|
onEnterPress,
|
|
|
|
onChange
|
2023-10-19 08:46:04 +00:00
|
|
|
}
|
2023-10-24 09:00:54 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
charCount () {
|
|
|
|
return (this.compVal) ? this.compVal.length : 0
|
|
|
|
}
|
2022-09-20 19:59:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|