opnform/resources/js/components/forms/TextInput.vue

83 lines
2.7 KiB
Vue
Raw Normal View History

2022-09-20 19:59:52 +00:00
<template>
<div :class="wrapperClass" :style="inputStyle">
2022-10-17 15:08:36 +00:00
<slot name="label">
2023-10-19 08:46:04 +00:00
<input-label v-if="label"
:label="label"
:theme="theme"
:required="true"
:native-for="id?id:name"
:uppercase-labels="uppercaseLabels"
/>
2022-10-17 15:08:36 +00:00
</slot>
2023-10-19 08:46:04 +00:00
<input-help v-if="help && helpPosition=='above_input'" :help="help" :theme="theme">
<template #help>
<slot name="help" />
</template>
</input-help>
2022-09-20 19:59:52 +00:00
<input :id="id?id:name" v-model="compVal" :disabled="disabled"
:type="nativeType"
: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-19 08:46:04 +00:00
<!-- <input-help v-if="(help && helpPosition=='below_input') || showCharLimit" :help="help" :theme="theme">-->
<!-- <template v-if="showCharLimit" #after-help>-->
<!-- <small v-if="showCharLimit && maxCharLimit" :class="theme.default.help">-->
<!-- {{ charCount }}/{{ maxCharLimit }}-->
<!-- </small>-->
<!-- </template>-->
<!-- </input-help>-->
2022-09-20 19:59:52 +00:00
<has-error v-if="hasValidation" :form="form" :field="name" />
</div>
</template>
<script>
2023-10-19 08:46:04 +00:00
import { inputProps, useFormInput } from './useFormInput.js'
import InputLabel from './components/InputLabel.vue'
import InputHelp from './components/InputHelp.vue'
2022-09-20 19:59:52 +00:00
export default {
name: 'TextInput',
2023-10-19 08:46:04 +00:00
components: { InputHelp, InputLabel },
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 },
pattern: { type: String, default: null }
2022-09-20 19:59:52 +00:00
},
2023-10-19 08:46:04 +00:00
setup (props) {
const { compVal, inputStyle, hasValidation, hasError } = useFormInput(props)
2022-09-20 19:59:52 +00:00
2023-10-19 08:46:04 +00:00
const onChange = (event) => {
console.log(props)
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 {
compVal,
inputStyle,
hasValidation,
hasError
}
2022-09-20 19:59:52 +00:00
}
}
</script>