input component updates

This commit is contained in:
Forms Dev 2023-11-28 13:17:40 +05:30
parent ee4cb7a0d3
commit 387a110820
5 changed files with 139 additions and 82 deletions

View File

@ -35,7 +35,7 @@
"vue-meta": "^3.0.0-alpha.2", "vue-meta": "^3.0.0-alpha.2",
"vue-notion": "^3.0.0-beta.1", "vue-notion": "^3.0.0-beta.1",
"vue-router": "^4.2.5", "vue-router": "^4.2.5",
"vue-signature-pad": "^2.0.5", "vue-signature-pad": "^3.0.2",
"vue2-editor": "^2.10.3", "vue2-editor": "^2.10.3",
"vue3-vt-notifications": "^1.0.0", "vue3-vt-notifications": "^1.0.0",
"vuedraggable": "^4.1.0", "vuedraggable": "^4.1.0",

View File

@ -1,14 +1,10 @@
<template> <template>
<div :class="wrapperClass"> <input-wrapper
<label v-if="label" :for="id?id:name" v-bind="$props"
:class="[theme.default.label,{'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]" >
> <template #label>
{{ label }} <slot name="label" />
<span v-if="required" class="text-red-500 required-dot">*</span> </template>
</label>
<small v-if="help && helpPosition=='above_input'" :class="theme.default.help" class="flex mb-1">
<slot name="help"><span class="field-help" v-html="help"/></slot>
</small>
<div class="flex" v-if="!dateRange"> <div class="flex" v-if="!dateRange">
<input :type="useTime ? 'datetime-local' : 'date'" :id="id?id:name" v-model="fromDate" :class="inputClasses" <input :type="useTime ? 'datetime-local' : 'date'" :id="id?id:name" v-model="fromDate" :class="inputClasses"
@ -34,28 +30,49 @@
</div> </div>
</div> </div>
<small v-if="help && helpPosition=='below_input'" :class="theme.default.help"> <template #help>
<slot name="help"><span class="field-help" v-html="help"/></slot> <slot name="help" />
</small> </template>
<has-error v-if="hasValidation" :form="form" :field="name"/> <template #error>
</div> <slot name="error" />
</template>
</input-wrapper>
</template> </template>
<script> <script>
import { inputProps, useFormInput } from './useFormInput.js'
import InputWrapper from './components/InputWrapper.vue'
import {fixedClasses} from '../../plugins/config/vue-tailwind/datePicker.js' import {fixedClasses} from '../../plugins/config/vue-tailwind/datePicker.js'
import inputMixin from '~/mixins/forms/input.js'
export default { export default {
name: 'DateInput', name: 'DateInput',
mixins: [inputMixin], components: { InputWrapper },
mixins: [],
props: { props: {
...inputProps,
withTime: {type: Boolean, default: false}, withTime: {type: Boolean, default: false},
dateRange: {type: Boolean, default: false}, dateRange: {type: Boolean, default: false},
disablePastDates: {type: Boolean, default: false}, disablePastDates: {type: Boolean, default: false},
disableFutureDates: {type: Boolean, default: false} disableFutureDates: {type: Boolean, default: false}
}, },
setup (props, context) {
const {
compVal,
inputStyle,
hasValidation,
hasError
} = useFormInput(props, context)
return {
compVal,
inputStyle,
hasValidation,
hasError
}
},
data: () => ({ data: () => ({
fixedClasses: fixedClasses, fixedClasses: fixedClasses,
fromDate: null, fromDate: null,

View File

@ -1,14 +1,10 @@
<template> <template>
<div :class="wrapperClass"> <input-wrapper
<label v-if="label" :for="id?id:name" v-bind="$props"
:class="[theme.default.label,{'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]" >
> <template #label>
{{ label }} <slot name="label" />
<span v-if="required" class="text-red-500 required-dot">*</span> </template>
</label>
<small v-if="help && helpPosition=='above_input'" :class="theme.SelectInput.help" class="block mb-1">
<slot name="help"><span class="field-help" v-html="help" /></slot>
</small>
<loader v-if="loading" key="loader" class="h-6 w-6 text-nt-blue mx-auto" /> <loader v-if="loading" key="loader" class="h-6 w-6 text-nt-blue mx-auto" />
<div v-for="(option, index) in options" v-else :key="option[optionKey]" role="button" <div v-for="(option, index) in options" v-else :key="option[optionKey]" role="button"
@ -25,24 +21,28 @@
</div> </div>
</div> </div>
<small v-if="help && helpPosition=='below_input'" :class="theme.SelectInput.help" class="block"> <template #help>
<slot name="help"><span class="field-help" v-html="help" /></slot> <slot name="help" />
</small> </template>
<has-error v-if="hasValidation" :form="form" :field="name" /> <template #error>
</div> <slot name="error" />
</template>
</input-wrapper>
</template> </template>
<script> <script>
import inputMixin from '~/mixins/forms/input.js' import { inputProps, useFormInput } from './useFormInput.js'
import InputWrapper from './components/InputWrapper.vue'
/** /**
* Options: {name,value} objects * Options: {name,value} objects
*/ */
export default { export default {
name: 'FlatSelectInput', name: 'FlatSelectInput',
mixins: [inputMixin], components: { InputWrapper },
props: { props: {
...inputProps,
options: { type: Array, required: true }, options: { type: Array, required: true },
optionKey: { type: String, default: 'value' }, optionKey: { type: String, default: 'value' },
emitKey: { type: String, default: 'value' }, emitKey: { type: String, default: 'value' },
@ -50,6 +50,21 @@ export default {
loading: { type: Boolean, default: false }, loading: { type: Boolean, default: false },
multiple: { type: Boolean, default: false } multiple: { type: Boolean, default: false }
}, },
setup (props, context) {
const {
compVal,
inputStyle,
hasValidation,
hasError
} = useFormInput(props, context)
return {
compVal,
inputStyle,
hasValidation,
hasError
}
},
data () { data () {
return {} return {}
}, },

View File

@ -1,16 +1,10 @@
<template> <template>
<div :class="wrapperClass"> <input-wrapper
<label v-if="label" :for="id?id:name" v-bind="$props"
:class="[theme.CodeInput.label,{'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]" >
> <template #label>
{{ label }} <slot name="label" />
<span v-if="required" class="text-red-500 required-dot">*</span> </template>
</label>
<div v-if="help && helpPosition=='above_input'" class="flex mb-1">
<small :class="theme.default.help" class="flex-grow">
<slot name="help"><span class="field-help" v-html="help" /></slot>
</small>
</div>
<VueSignaturePad ref="signaturePad" <VueSignaturePad ref="signaturePad"
:class="[theme.default.input,{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }]" height="150px" :class="[theme.default.input,{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }]" height="150px"
@ -19,30 +13,48 @@
/> />
<div class="flex"> <div class="flex">
<small v-if="help && helpPosition=='below_input'" :class="theme.default.help" class="flex-grow">
<slot name="help"><span class="field-help" v-html="help" /></slot>
</small>
<small v-else class="flex-grow" />
<small :class="theme.default.help"> <small :class="theme.default.help">
<a :class="theme.default.help" href="#" @click.prevent="clear">Clear</a> <a :class="theme.default.help" href="#" @click.prevent="clear">Clear</a>
</small> </small>
</div> </div>
<has-error v-if="hasValidation" :form="form" :field="name" />
</div> <template #help>
<slot name="help" />
</template>
<template #error>
<slot name="error" />
</template>
</input-wrapper>
</template> </template>
<script> <script>
import Vue from 'vue' import { inputProps, useFormInput } from './useFormInput.js'
import InputWrapper from './components/InputWrapper.vue'
import VueSignaturePad from 'vue-signature-pad' import VueSignaturePad from 'vue-signature-pad'
import inputMixin from '~/mixins/forms/input.js'
Vue.use(VueSignaturePad)
export default { export default {
name: 'SignatureInput', name: 'SignatureInput',
components: {InputWrapper, VueSignaturePad},
components: {}, props: {
mixins: [inputMixin], ...inputProps,
},
setup (props, context) {
const {
compVal,
inputStyle,
hasValidation,
hasError
} = useFormInput(props, context)
return {
compVal,
inputStyle,
hasValidation,
hasError
}
},
methods: { methods: {
clear () { clear () {

View File

@ -1,16 +1,11 @@
<template> <template>
<div :class="wrapperClass"> <input-wrapper
<label v-if="label" :for="id?id:name" v-bind="$props"
:class="[theme.default.label, {'uppercase text-xs':uppercaseLabels, 'text-sm':!uppercaseLabels}]" >
> <template #label>
{{ label }} <slot name="label" />
<span v-if="required" class="text-red-500 required-dot">*</span> </template>
</label>
<div v-if="help && helpPosition=='above_input'" class="flex mb-1">
<small :class="theme.default.help" class="flex-grow">
<slot name="help"><span class="field-help" v-html="help" /></slot>
</small>
</div>
<textarea :id="id?id:name" v-model="compVal" :disabled="disabled" <textarea :id="id?id:name" v-model="compVal" :disabled="disabled"
:class="[theme.default.input,{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }]" :class="[theme.default.input,{ '!ring-red-500 !ring-2': hasValidation && form.errors.has(name), '!cursor-not-allowed !bg-gray-200':disabled }]"
class="resize-y" class="resize-y"
@ -18,30 +13,48 @@
:placeholder="placeholder" :placeholder="placeholder"
:maxlength="maxCharLimit" :maxlength="maxCharLimit"
/> />
<div v-if="(help && helpPosition=='below_input') || showCharLimit" class="flex">
<small v-if="help && helpPosition=='below_input'" :class="theme.default.help" class="flex-grow"> <template v-if="maxCharLimit && showCharLimit" #bottom_after_help>
<slot name="help"><span class="field-help" v-html="help" /></slot> <small :class="theme.default.help">
</small>
<small v-else class="flex-grow"></small>
<small v-if="showCharLimit && maxCharLimit" :class="theme.default.help">
{{ charCount }}/{{ maxCharLimit }} {{ charCount }}/{{ maxCharLimit }}
</small> </small>
</div> </template>
<has-error v-if="hasValidation" :form="form" :field="name" />
</div> <template #error>
<slot name="error" />
</template>
</input-wrapper>
</template> </template>
<script> <script>
import inputMixin from '~/mixins/forms/input.js' import { inputProps, useFormInput } from './useFormInput.js'
import InputWrapper from './components/InputWrapper.vue'
export default { export default {
name: 'TextAreaInput', name: 'TextAreaInput',
mixins: [inputMixin], components: { InputWrapper },
mixins: [],
props: { props: {
...inputProps,
maxCharLimit: { type: Number, required: false, default: null }, maxCharLimit: { type: Number, required: false, default: null },
showCharLimit: { type: Boolean, required: false, default: false }, showCharLimit: { type: Boolean, required: false, default: false },
}, },
setup (props, context) {
const {
compVal,
inputStyle,
hasValidation,
hasError
} = useFormInput(props, context)
return {
compVal,
inputStyle,
hasValidation,
hasError
}
},
computed: { computed: {
charCount() { charCount() {
return (this.compVal) ? this.compVal.length : 0 return (this.compVal) ? this.compVal.length : 0