Separate input type for Rating,Scale,Slider (#351)
* Separate input type for Rating,Scale,Slider * rating, scale, slider add in test cases * Allow field type change for new types * Added options to db factory * Fix linting --------- Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
@@ -109,7 +109,7 @@ export default {
|
||||
return this.field && this.field.type.startsWith('nf')
|
||||
},
|
||||
typeCanBeChanged () {
|
||||
return ['text', 'email', 'phone_number', 'number', 'select', 'multi_select'].includes(this.field.type)
|
||||
return ['text', 'email', 'phone_number', 'number', 'select', 'multi_select', 'rating', 'scale', 'slider'].includes(this.field.type)
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<dropdown v-if="changeTypeOptions.length > 0" dusk="nav-dropdown">
|
||||
<dropdown ref="newTypeDropdown" v-if="changeTypeOptions.length > 0" dusk="nav-dropdown">
|
||||
<template #trigger="{toggle}">
|
||||
<v-button class="relative" :class="btnClasses" size="small" color="light-gray" @click.stop="toggle">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="h-4 w-4 text-blue-600 inline mr-1 -mt-1">
|
||||
@@ -41,12 +41,15 @@ export default {
|
||||
computed: {
|
||||
changeTypeOptions () {
|
||||
let newTypes = []
|
||||
if (['text', 'email', 'phone_number', 'number'].includes(this.field.type)) {
|
||||
if (['text', 'email', 'phone_number', 'number','slider','rating','scale'].includes(this.field.type)) {
|
||||
newTypes = [
|
||||
{ name: 'Text Input', value: 'text' },
|
||||
{ name: 'Email Input', value: 'email' },
|
||||
{ name: 'Phone Input', value: 'phone_number' },
|
||||
{ name: 'Number Input', value: 'number' }
|
||||
{ name: 'Number Input', value: 'number' },
|
||||
{ name: 'Slider Input', value: 'slider' },
|
||||
{ name: 'Rating Input', value: 'rating' },
|
||||
{ name: 'Scale Input', value: 'scale' },
|
||||
]
|
||||
}
|
||||
if (['select', 'multi_select'].includes(this.field.type)) {
|
||||
@@ -75,6 +78,7 @@ export default {
|
||||
changeType (newType) {
|
||||
if (newType) {
|
||||
this.$emit('changeType', newType)
|
||||
this.$refs.newTypeDropdown.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,22 +8,16 @@
|
||||
<p class="text-gray-400 mb-2 text-xs">
|
||||
Exclude this field or make it required.
|
||||
</p>
|
||||
<v-checkbox v-model="field.hidden" class="mb-3"
|
||||
:name="field.id+'_hidden'"
|
||||
@update:model-value="onFieldHiddenChange"
|
||||
>
|
||||
<v-checkbox v-model="field.hidden" class="mb-3" :name="field.id + '_hidden'"
|
||||
@update:model-value="onFieldHiddenChange">
|
||||
Hidden
|
||||
</v-checkbox>
|
||||
<v-checkbox v-model="field.required" class="mb-3"
|
||||
:name="field.id+'_required'"
|
||||
@update:model-value="onFieldRequiredChange"
|
||||
>
|
||||
<v-checkbox v-model="field.required" class="mb-3" :name="field.id + '_required'"
|
||||
@update:model-value="onFieldRequiredChange">
|
||||
Required
|
||||
</v-checkbox>
|
||||
<v-checkbox v-model="field.disabled" class="mb-3"
|
||||
:name="field.id+'_disabled'"
|
||||
@update:model-value="onFieldDisabledChange"
|
||||
>
|
||||
<v-checkbox v-model="field.disabled" class="mb-3" :name="field.id + '_disabled'"
|
||||
@update:model-value="onFieldDisabledChange">
|
||||
Disabled
|
||||
</v-checkbox>
|
||||
</div>
|
||||
@@ -36,9 +30,7 @@
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Advanced options for checkbox.
|
||||
</p>
|
||||
<v-checkbox v-model="field.use_toggle_switch" class="mt-3"
|
||||
name="use_toggle_switch" help=""
|
||||
>
|
||||
<v-checkbox v-model="field.use_toggle_switch" class="mt-3" name="use_toggle_switch" help="">
|
||||
Use toggle switch
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
@@ -51,88 +43,56 @@
|
||||
<h3 class="font-semibold block text-lg">
|
||||
File uploads
|
||||
</h3>
|
||||
<v-checkbox v-model="field.multiple" class="mt-3"
|
||||
:name="field.id+'_multiple'"
|
||||
>
|
||||
<v-checkbox v-model="field.multiple" class="mt-3" :name="field.id + '_multiple'">
|
||||
Allow multiple files
|
||||
</v-checkbox>
|
||||
<text-input name="allowed_file_types" class="mt-3" :form="field"
|
||||
label="Allowed file types" placeholder="jpg,jpeg,png,gif"
|
||||
help="Comma separated values, leave blank to allow all file types"
|
||||
/>
|
||||
<text-input name="allowed_file_types" class="mt-3" :form="field" label="Allowed file types"
|
||||
placeholder="jpg,jpeg,png,gif" help="Comma separated values, leave blank to allow all file types" />
|
||||
|
||||
<text-input name="max_file_size" class="mt-3" :form="field" native-type="number"
|
||||
:min="1"
|
||||
:max="mbLimit"
|
||||
label="Maximum file size (in MB)" :placeholder="`1MB - ${mbLimit}MB`"
|
||||
help="Set the maximum file size that can be uploaded"
|
||||
/>
|
||||
<text-input name="max_file_size" class="mt-3" :form="field" native-type="number" :min="1" :max="mbLimit"
|
||||
label="Maximum file size (in MB)" :placeholder="`1MB - ${mbLimit}MB`"
|
||||
help="Set the maximum file size that can be uploaded" />
|
||||
</div>
|
||||
|
||||
<!-- Number Options -->
|
||||
<div v-if="field.type === 'number'" class="border-b py-2 px-4">
|
||||
<div v-if="field.type === 'rating'" class="border-b py-2 px-4">
|
||||
<h3 class="font-semibold block text-lg">
|
||||
Number Options
|
||||
</h3>
|
||||
<v-checkbox v-model="field.is_rating" class="mt-3"
|
||||
:name="field.id+'_is_rating'" @update:model-value="initRating"
|
||||
>
|
||||
Rating
|
||||
</v-checkbox>
|
||||
</h3>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Transform this field into a star rating input.
|
||||
Advanced options for rating.
|
||||
</p>
|
||||
<text-input name="rating_max_value" native-type="number" :min="1" class="mt-3" :form="field" required
|
||||
label="Max rating value" />
|
||||
</div>
|
||||
|
||||
<text-input v-if="field.is_rating" name="rating_max_value" native-type="number" :min="1" class="mt-3"
|
||||
:form="field" required
|
||||
label="Max rating value"
|
||||
/>
|
||||
|
||||
<v-checkbox v-model="field.is_scale" class="mt-4"
|
||||
:name="field.id+'_is_scale'" @update:model-value="initScale"
|
||||
>
|
||||
<div v-if="field.type === 'scale'" class="border-b py-2 px-4">
|
||||
<h3 class="font-semibold block text-lg">
|
||||
Scale
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 text-xs mb-5">
|
||||
Transform this field into a scale/score input.
|
||||
</h3>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Advanced options for scale.
|
||||
</p>
|
||||
<template v-if="field.is_scale">
|
||||
<text-input name="scale_min_value" native-type="number" class="mt-4"
|
||||
:form="field" required
|
||||
label="Min scale value"
|
||||
/>
|
||||
<text-input name="scale_max_value" native-type="number" :min="1" class="mt-4"
|
||||
:form="field" required
|
||||
label="Max scale value"
|
||||
/>
|
||||
<text-input name="scale_step_value" native-type="number" :min="1" class="mt-4"
|
||||
:form="field" required
|
||||
label="Scale steps value"
|
||||
/>
|
||||
</template>
|
||||
<text-input name="scale_min_value" native-type="number" class="mt-4" :form="field" required
|
||||
label="Min scale value" />
|
||||
<text-input name="scale_max_value" native-type="number" :min="1" class="mt-4" :form="field" required
|
||||
label="Max scale value" />
|
||||
<text-input name="scale_step_value" native-type="number" :min="1" class="mt-4" :form="field" required
|
||||
label="Scale steps value" />
|
||||
</div>
|
||||
|
||||
<v-checkbox v-model="field.is_slider" class="mt-4"
|
||||
:name="field.id+'_is_slider'" @update:model-value="initSlider"
|
||||
>
|
||||
<div v-if="field.type === 'slider'" class="border-b py-2 px-4">
|
||||
<h3 class="font-semibold block text-lg">
|
||||
Slider
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 text-xs mb-5">
|
||||
Transform this field into a slider input.
|
||||
</h3>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Advanced options for slider.
|
||||
</p>
|
||||
<template v-if="field.is_slider">
|
||||
<text-input name="slider_min_value" native-type="number" class="mt-4"
|
||||
:form="field" required
|
||||
label="Min slider value"
|
||||
/>
|
||||
<text-input name="slider_max_value" native-type="number" :min="1" class="mt-4"
|
||||
:form="field" required
|
||||
label="Max slider value"
|
||||
/>
|
||||
<text-input name="slider_step_value" native-type="number" :min="1" class="mt-4"
|
||||
:form="field" required
|
||||
label="Slider steps value"
|
||||
/>
|
||||
</template>
|
||||
<text-input name="slider_min_value" native-type="number" class="mt-4" :form="field" required
|
||||
label="Min slider value" />
|
||||
<text-input name="slider_max_value" native-type="number" :min="1" class="mt-4" :form="field" required
|
||||
label="Max slider value" />
|
||||
<text-input name="slider_step_value" native-type="number" :min="1" class="mt-4" :form="field" required
|
||||
label="Slider steps value" />
|
||||
</div>
|
||||
|
||||
<!-- Text Options -->
|
||||
@@ -143,10 +103,8 @@
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Keep it simple or make it a multi-lines input.
|
||||
</p>
|
||||
<v-checkbox v-model="field.multi_lines" class="mb-2"
|
||||
:name="field.id+'_multi_lines'"
|
||||
@update:model-value="field.multi_lines = $event"
|
||||
>
|
||||
<v-checkbox v-model="field.multi_lines" class="mb-2" :name="field.id + '_multi_lines'"
|
||||
@update:model-value="field.multi_lines = $event">
|
||||
Multi-lines input
|
||||
</v-checkbox>
|
||||
</div>
|
||||
@@ -156,76 +114,56 @@
|
||||
<h3 class="font-semibold block text-lg">
|
||||
Date Options
|
||||
</h3>
|
||||
<v-checkbox v-model="field.date_range" class="mt-3"
|
||||
:name="field.id+'_date_range'"
|
||||
@update:model-value="onFieldDateRangeChange"
|
||||
>
|
||||
<v-checkbox v-model="field.date_range" class="mt-3" :name="field.id + '_date_range'"
|
||||
@update:model-value="onFieldDateRangeChange">
|
||||
Date Range
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Adds an end date. This cannot be used with the time option yet.
|
||||
</p>
|
||||
<v-checkbox v-model="field.with_time"
|
||||
:name="field.id+'_with_time'"
|
||||
@update:model-value="onFieldWithTimeChange"
|
||||
>
|
||||
<v-checkbox v-model="field.with_time" :name="field.id + '_with_time'" @update:model-value="onFieldWithTimeChange">
|
||||
Date with time
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Include time. Or not. This cannot be used with the date range option yet.
|
||||
</p>
|
||||
|
||||
<select-input v-if="field.with_time" name="timezone" class="mt-3"
|
||||
:form="field" :options="timezonesOptions"
|
||||
label="Timezone" :searchable="true"
|
||||
help="Make sure to select correct timezone. Leave blank otherwise."
|
||||
/>
|
||||
<v-checkbox v-model="field.prefill_today"
|
||||
name="prefill_today"
|
||||
@update:model-value="onFieldPrefillTodayChange"
|
||||
>
|
||||
<select-input v-if="field.with_time" name="timezone" class="mt-3" :form="field" :options="timezonesOptions"
|
||||
label="Timezone" :searchable="true" help="Make sure to select correct timezone. Leave blank otherwise." />
|
||||
<v-checkbox v-model="field.prefill_today" name="prefill_today" @update:model-value="onFieldPrefillTodayChange">
|
||||
Prefill with 'today'
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
if enabled we will pre-fill this field with the current date
|
||||
</p>
|
||||
|
||||
<v-checkbox v-model="field.disable_past_dates"
|
||||
name="disable_past_dates" class="mb-3"
|
||||
@update:model-value="onFieldDisablePastDatesChange"
|
||||
>
|
||||
<v-checkbox v-model="field.disable_past_dates" name="disable_past_dates" class="mb-3"
|
||||
@update:model-value="onFieldDisablePastDatesChange">
|
||||
Disable past dates
|
||||
</v-checkbox>
|
||||
|
||||
<v-checkbox v-model="field.disable_future_dates"
|
||||
name="disable_future_dates" class="mb-3"
|
||||
@update:model-value="onFieldDisableFutureDatesChange"
|
||||
>
|
||||
<v-checkbox v-model="field.disable_future_dates" name="disable_future_dates" class="mb-3"
|
||||
@update:model-value="onFieldDisableFutureDatesChange">
|
||||
Disable future dates
|
||||
</v-checkbox>
|
||||
</div>
|
||||
|
||||
<!-- select/multiselect Options -->
|
||||
<div v-if="['select','multi_select'].includes(field.type)" class="border-b py-2 px-4">
|
||||
<div v-if="['select', 'multi_select'].includes(field.type)" class="border-b py-2 px-4">
|
||||
<h3 class="font-semibold block text-lg">
|
||||
Select Options
|
||||
</h3>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
Advanced options for your select/multiselect fields.
|
||||
</p>
|
||||
<text-area-input v-model="optionsText" :name="field.id+'_options_text'" class="mt-3"
|
||||
label="Set selection options"
|
||||
help="Add one option per line"
|
||||
@update:model-value="onFieldOptionsChange"
|
||||
/>
|
||||
<v-checkbox v-model="field.allow_creation"
|
||||
name="allow_creation" help="" @update:model-value="onFieldAllowCreationChange"
|
||||
>
|
||||
<text-area-input v-model="optionsText" :name="field.id + '_options_text'" class="mt-3"
|
||||
label="Set selection options" help="Add one option per line" @update:model-value="onFieldOptionsChange" />
|
||||
<v-checkbox v-model="field.allow_creation" name="allow_creation" help=""
|
||||
@update:model-value="onFieldAllowCreationChange">
|
||||
Allow respondent to create new options
|
||||
</v-checkbox>
|
||||
<v-checkbox v-model="field.without_dropdown" class="mt-3"
|
||||
name="without_dropdown" help="" @update:model-value="onFieldWithoutDropdownChange"
|
||||
>
|
||||
<v-checkbox v-model="field.without_dropdown" class="mt-3" name="without_dropdown" help=""
|
||||
@update:model-value="onFieldWithoutDropdownChange">
|
||||
Always show all select options
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
@@ -243,35 +181,27 @@
|
||||
Change your form field name, pre-fill a value, add hints, etc.
|
||||
</p>
|
||||
|
||||
<text-input name="name" class="mt-3"
|
||||
:form="field" :required="true"
|
||||
label="Field Name"
|
||||
/>
|
||||
<text-input name="name" class="mt-3" :form="field" :required="true" label="Field Name" />
|
||||
|
||||
<v-checkbox v-model="field.hide_field_name" class="mt-3"
|
||||
:name="field.id+'_hide_field_name'"
|
||||
>
|
||||
<v-checkbox v-model="field.hide_field_name" class="mt-3" :name="field.id + '_hide_field_name'">
|
||||
Hide field name
|
||||
</v-checkbox>
|
||||
|
||||
<v-checkbox v-if="field.type === 'phone_number'" v-model="field.use_simple_text_input" class="mt-3"
|
||||
:name="field.id+'_use_simple_text_input'"
|
||||
>
|
||||
:name="field.id + '_use_simple_text_input'">
|
||||
Use simple text input
|
||||
</v-checkbox>
|
||||
<template v-if="field.type === 'phone_number' && !field.use_simple_text_input">
|
||||
<select-input v-model="field.unavailable_countries" class="mt-4" wrapper-class="relative"
|
||||
:options="allCountries" :multiple="true"
|
||||
:searchable="true" :search-keys="['name']" :option-key="'code'" :emit-key="'code'"
|
||||
label="Disabled countries" :placeholder="'Select a country'"
|
||||
help="Remove countries from the phone input"
|
||||
>
|
||||
<template #selected="{option, selected}">
|
||||
:options="allCountries" :multiple="true" :searchable="true" :search-keys="['name']" :option-key="'code'"
|
||||
:emit-key="'code'" label="Disabled countries" :placeholder="'Select a country'"
|
||||
help="Remove countries from the phone input">
|
||||
<template #selected="{ option, selected }">
|
||||
<div class="flex items-center space-x-2 justify-center overflow-hidden">
|
||||
{{ option.length }} selected
|
||||
</div>
|
||||
</template>
|
||||
<template #option="{option, selected}">
|
||||
<template #option="{ option, selected }">
|
||||
<div class="flex items-center space-x-2 hover:text-white">
|
||||
<country-flag size="normal" class="!-mt-[9px]" :country="option.code" />
|
||||
<span class="grow">{{ option.name }}</span>
|
||||
@@ -280,106 +210,70 @@
|
||||
<span v-if="selected" class="absolute inset-y-0 right-0 flex items-center pr-2 dark:text-white">
|
||||
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd"
|
||||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
|
||||
clip-rule="evenodd" />
|
||||
</svg>
|
||||
</span>
|
||||
</template>
|
||||
</select-input>
|
||||
<small class="flex -mt-2">
|
||||
<a href="#" class="grow" @click.prevent="selectAllCountries">Select All</a>
|
||||
<a href="#" @click.prevent="field.unavailable_countries=null">Un-select All</a>
|
||||
<a href="#" @click.prevent="field.unavailable_countries = null">Un-select All</a>
|
||||
</small>
|
||||
</template>
|
||||
|
||||
<!-- Pre-fill depends on type -->
|
||||
<v-checkbox v-if="field.type=='checkbox'" v-model="field.prefill" class="mt-3"
|
||||
:name="field.id+'_prefill'"
|
||||
@update:model-value="field.prefill = $event"
|
||||
>
|
||||
<v-checkbox v-if="field.type == 'checkbox'" v-model="field.prefill" class="mt-3" :name="field.id + '_prefill'"
|
||||
@update:model-value="field.prefill = $event">
|
||||
Pre-filled value
|
||||
</v-checkbox>
|
||||
<select-input v-else-if="['select','multi_select'].includes(field.type)" name="prefill" class="mt-3"
|
||||
:form="field" :options="prefillSelectsOptions"
|
||||
label="Pre-filled value"
|
||||
:multiple="field.type==='multi_select'"
|
||||
/>
|
||||
<date-input v-else-if="field.type==='date' && field.prefill_today!==true" name="prefill" class="mt-3"
|
||||
:form="field" :with-time="field.with_time===true"
|
||||
:date-range="field.date_range===true"
|
||||
label="Pre-filled value"
|
||||
/>
|
||||
<phone-input v-else-if="field.type === 'phone_number' && !field.use_simple_text_input"
|
||||
name="prefill" class="mt-3"
|
||||
:form="field" :can-only-country="true" :unavailable-countries="field.unavailable_countries ?? []"
|
||||
label="Pre-filled value"
|
||||
/>
|
||||
<text-area-input v-else-if="field.type === 'text' && field.multi_lines"
|
||||
name="prefill" class="mt-3"
|
||||
:form="field"
|
||||
label="Pre-filled value"
|
||||
/>
|
||||
<file-input v-else-if="field.type==='files'" name="prefill" class="mt-4"
|
||||
:form="field"
|
||||
label="Pre-filled file"
|
||||
:multiple="field.multiple===true" :move-to-form-assets="true"
|
||||
/>
|
||||
<text-input v-else-if="!['files', 'signature'].includes(field.type)" name="prefill" class="mt-3"
|
||||
:form="field"
|
||||
label="Pre-filled value"
|
||||
/>
|
||||
<div v-if="['select','multi_select'].includes(field.type)" class="-mt-3 mb-3 text-gray-400 dark:text-gray-500">
|
||||
<select-input v-else-if="['select', 'multi_select'].includes(field.type)" name="prefill" class="mt-3"
|
||||
:form="field" :options="prefillSelectsOptions" label="Pre-filled value"
|
||||
:multiple="field.type === 'multi_select'" />
|
||||
<date-input v-else-if="field.type === 'date' && field.prefill_today !== true" name="prefill" class="mt-3"
|
||||
:form="field" :with-time="field.with_time === true" :date-range="field.date_range === true"
|
||||
label="Pre-filled value" />
|
||||
<phone-input v-else-if="field.type === 'phone_number' && !field.use_simple_text_input" name="prefill" class="mt-3"
|
||||
:form="field" :can-only-country="true" :unavailable-countries="field.unavailable_countries ?? []"
|
||||
label="Pre-filled value" />
|
||||
<text-area-input v-else-if="field.type === 'text' && field.multi_lines" name="prefill" class="mt-3" :form="field"
|
||||
label="Pre-filled value" />
|
||||
<file-input v-else-if="field.type === 'files'" name="prefill" class="mt-4" :form="field" label="Pre-filled file"
|
||||
:multiple="field.multiple === true" :move-to-form-assets="true" />
|
||||
<text-input v-else-if="!['files', 'signature'].includes(field.type)" name="prefill" class="mt-3" :form="field"
|
||||
label="Pre-filled value" />
|
||||
<div v-if="['select', 'multi_select'].includes(field.type)" class="-mt-3 mb-3 text-gray-400 dark:text-gray-500">
|
||||
<small>
|
||||
A problem? <a href="#" @click.prevent="field.prefill=null">Click here to clear your pre-fill</a>
|
||||
A problem? <a href="#" @click.prevent="field.prefill = null">Click here to clear your pre-fill</a>
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<!-- Placeholder -->
|
||||
<text-input v-if="hasPlaceholder" name="placeholder" class="mt-3"
|
||||
:form="field"
|
||||
label="Empty Input Text (Placeholder)"
|
||||
/>
|
||||
<text-input v-if="hasPlaceholder" name="placeholder" class="mt-3" :form="field"
|
||||
label="Empty Input Text (Placeholder)" />
|
||||
|
||||
<select-input name="width" class="mt-3"
|
||||
:options="[
|
||||
{name:'Full',value:'full'},
|
||||
{name:'1/2 (half width)',value:'1/2'},
|
||||
{name:'1/3 (a third of the width)',value:'1/3'},
|
||||
{name:'2/3 (two thirds of the width)',value:'2/3'},
|
||||
{name:'1/4 (a quarter of the width)',value:'1/4'},
|
||||
{name:'3/4 (three quarters of the width)',value:'3/4'},
|
||||
]"
|
||||
:form="field" label="Field Width"
|
||||
/>
|
||||
<select-input name="width" class="mt-3" :options="[
|
||||
{ name: 'Full', value: 'full' },
|
||||
{ name: '1/2 (half width)', value: '1/2' },
|
||||
{ name: '1/3 (a third of the width)', value: '1/3' },
|
||||
{ name: '2/3 (two thirds of the width)', value: '2/3' },
|
||||
{ name: '1/4 (a quarter of the width)', value: '1/4' },
|
||||
{ name: '3/4 (three quarters of the width)', value: '3/4' },
|
||||
]" :form="field" label="Field Width" />
|
||||
|
||||
<!-- Help -->
|
||||
<rich-text-area-input name="help" class="mt-3"
|
||||
:form="field"
|
||||
:editor-toolbar="editorToolbarCustom"
|
||||
label="Field Help"
|
||||
help="Your field help will be shown below/above the field, just like this message."
|
||||
:help-position="field.help_position"
|
||||
/>
|
||||
<select-input name="help_position" class="mt-3"
|
||||
:options="[
|
||||
{name:'Below input',value:'below_input'},
|
||||
{name:'Above input',value:'above_input'},
|
||||
]"
|
||||
:form="field" label="Field Help Position"
|
||||
@update:model-value="onFieldHelpPositionChange"
|
||||
/>
|
||||
<rich-text-area-input name="help" class="mt-3" :form="field" :editor-toolbar="editorToolbarCustom"
|
||||
label="Field Help" help="Your field help will be shown below/above the field, just like this message."
|
||||
:help-position="field.help_position" />
|
||||
<select-input name="help_position" class="mt-3" :options="[
|
||||
{ name: 'Below input', value: 'below_input' },
|
||||
{ name: 'Above input', value: 'above_input' },
|
||||
]" :form="field" label="Field Help Position" @update:model-value="onFieldHelpPositionChange" />
|
||||
|
||||
<template v-if="['text','number','url','email'].includes(field.type)">
|
||||
<text-input name="max_char_limit" native-type="number" :min="1" :max="2000"
|
||||
:form="field"
|
||||
label="Max character limit"
|
||||
help="Maximum character limit of 2000"
|
||||
:required="false"
|
||||
/>
|
||||
<checkbox-input name="show_char_limit" :form="field" class="mt-3"
|
||||
label="Always show character limit"
|
||||
/>
|
||||
<template v-if="['text', 'number', 'url', 'email'].includes(field.type)">
|
||||
<text-input name="max_char_limit" native-type="number" :min="1" :max="2000" :form="field"
|
||||
label="Max character limit" help="Maximum character limit of 2000" :required="false" />
|
||||
<checkbox-input name="show_char_limit" :form="field" class="mt-3" label="Always show character limit" />
|
||||
</template>
|
||||
</div>
|
||||
|
||||
@@ -389,10 +283,8 @@
|
||||
Advanced Options
|
||||
</h3>
|
||||
|
||||
<v-checkbox v-model="field.generates_uuid"
|
||||
:name="field.id+'_generates_uuid'"
|
||||
@update:model-value="onFieldGenUIdChange"
|
||||
>
|
||||
<v-checkbox v-model="field.generates_uuid" :name="field.id + '_generates_uuid'"
|
||||
@update:model-value="onFieldGenUIdChange">
|
||||
Generates a unique id
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
@@ -400,10 +292,8 @@
|
||||
submission
|
||||
</p>
|
||||
|
||||
<v-checkbox v-model="field.generates_auto_increment_id"
|
||||
:name="field.id+'_generates_auto_increment_id'"
|
||||
@update:model-value="onFieldGenAutoIdChange"
|
||||
>
|
||||
<v-checkbox v-model="field.generates_auto_increment_id" :name="field.id + '_generates_auto_increment_id'"
|
||||
@update:model-value="onFieldGenAutoIdChange">
|
||||
Generates an auto-incremented id
|
||||
</v-checkbox>
|
||||
<p class="text-gray-400 mb-3 text-xs">
|
||||
@@ -438,7 +328,7 @@ export default {
|
||||
setup() {
|
||||
return { currentWorkspace: computed(() => useWorkspacesStore().getCurrent), }
|
||||
},
|
||||
data () {
|
||||
data() {
|
||||
return {
|
||||
typesWithoutPlaceholder: ['date', 'checkbox', 'files'],
|
||||
editorToolbarCustom: [
|
||||
@@ -449,13 +339,13 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
hasPlaceholder () {
|
||||
hasPlaceholder() {
|
||||
return !this.typesWithoutPlaceholder.includes(this.field.type)
|
||||
},
|
||||
mbLimit() {
|
||||
return this.form?.max_file_size ?? this.currentWorkspace?.max_file_size
|
||||
},
|
||||
prefillSelectsOptions () {
|
||||
prefillSelectsOptions() {
|
||||
if (!['select', 'multi_select'].includes(this.field.type)) return {}
|
||||
|
||||
return this.field[this.field.type].options.map(option => {
|
||||
@@ -465,7 +355,7 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
timezonesOptions () {
|
||||
timezonesOptions() {
|
||||
if (this.field.type !== 'date') return []
|
||||
return timezones.map((timezone) => {
|
||||
return {
|
||||
@@ -474,13 +364,13 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
displayBasedOnAdvanced () {
|
||||
displayBasedOnAdvanced() {
|
||||
if (this.field.generates_uuid || this.field.generates_auto_increment_id) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
optionsText () {
|
||||
optionsText() {
|
||||
if (!this.field[this.field.type]) return ''
|
||||
return this.field[this.field.type].options.map(option => {
|
||||
return option.name
|
||||
@@ -490,7 +380,7 @@ export default {
|
||||
|
||||
watch: {
|
||||
'field.width': {
|
||||
handler (val) {
|
||||
handler(val) {
|
||||
if (val === undefined || val === null) {
|
||||
this.field.width = 'full'
|
||||
}
|
||||
@@ -498,44 +388,45 @@ export default {
|
||||
immediate: true
|
||||
},
|
||||
'field.align': {
|
||||
handler (val) {
|
||||
handler(val) {
|
||||
if (val === undefined || val === null) {
|
||||
this.field.align = 'left'
|
||||
}
|
||||
},
|
||||
immediate: true
|
||||
}
|
||||
},
|
||||
'field.type': {
|
||||
handler() {
|
||||
this.setDefaultFieldValues()
|
||||
},
|
||||
immediate: true
|
||||
},
|
||||
},
|
||||
|
||||
created () {
|
||||
created() {
|
||||
if (this.field?.width === undefined || this.field?.width === null) {
|
||||
this.field.width = 'full'
|
||||
}
|
||||
},
|
||||
|
||||
mounted () {
|
||||
if (['text', 'number', 'url', 'email'].includes(this.field?.type) && !this.field?.max_char_limit) {
|
||||
this.field.max_char_limit = 2000
|
||||
}
|
||||
if (this.field.type == 'files') {
|
||||
this.field.max_file_size = Math.min((this.field.max_file_size ?? this.mbLimit), this.mbLimit)
|
||||
}
|
||||
mounted() {
|
||||
this.setDefaultFieldValues()
|
||||
},
|
||||
|
||||
methods: {
|
||||
onFieldDisabledChange (val) {
|
||||
onFieldDisabledChange(val) {
|
||||
this.field.disabled = val
|
||||
if (this.field.disabled) {
|
||||
this.field.hidden = false
|
||||
}
|
||||
},
|
||||
onFieldRequiredChange (val) {
|
||||
onFieldRequiredChange(val) {
|
||||
this.field.required = val
|
||||
if (this.field.required) {
|
||||
this.field.hidden = false
|
||||
}
|
||||
},
|
||||
onFieldHiddenChange (val) {
|
||||
onFieldHiddenChange(val) {
|
||||
this.field.hidden = val
|
||||
if (this.field.hidden) {
|
||||
this.field.required = false
|
||||
@@ -545,74 +436,34 @@ export default {
|
||||
this.field.generates_auto_increment_id = false
|
||||
}
|
||||
},
|
||||
onFieldDateRangeChange (val) {
|
||||
onFieldDateRangeChange(val) {
|
||||
this.field.date_range = val
|
||||
if (this.field.date_range) {
|
||||
this.field.with_time = false
|
||||
this.field.prefill_today = false
|
||||
}
|
||||
},
|
||||
onFieldWithTimeChange (val) {
|
||||
onFieldWithTimeChange(val) {
|
||||
this.field.with_time = val
|
||||
if (this.field.with_time) {
|
||||
this.field.date_range = false
|
||||
}
|
||||
},
|
||||
onFieldGenUIdChange (val) {
|
||||
onFieldGenUIdChange(val) {
|
||||
this.field.generates_uuid = val
|
||||
if (this.field.generates_uuid) {
|
||||
this.field.generates_auto_increment_id = false
|
||||
this.field.hidden = true
|
||||
}
|
||||
},
|
||||
onFieldGenAutoIdChange (val) {
|
||||
onFieldGenAutoIdChange(val) {
|
||||
this.field.generates_auto_increment_id = val
|
||||
if (this.field.generates_auto_increment_id) {
|
||||
this.field.generates_uuid = false
|
||||
this.field.hidden = true
|
||||
}
|
||||
},
|
||||
initRating () {
|
||||
if (this.field.is_rating) {
|
||||
this.field.is_scale = false
|
||||
this.field.is_slider = false
|
||||
if (!this.field.rating_max_value) {
|
||||
this.field.rating_max_value = 5
|
||||
}
|
||||
}
|
||||
},
|
||||
initScale () {
|
||||
if (this.field.is_scale) {
|
||||
this.field.is_rating = false
|
||||
this.field.is_slider = false
|
||||
if (!this.field.scale_min_value) {
|
||||
this.field.scale_min_value = 1
|
||||
}
|
||||
if (!this.field.scale_max_value) {
|
||||
this.field.scale_max_value = 5
|
||||
}
|
||||
if (!this.field.scale_step_value) {
|
||||
this.field.scale_step_value = 1
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
initSlider () {
|
||||
if (this.field.is_slider) {
|
||||
this.field.is_rating = false
|
||||
this.field.is_scale = false
|
||||
if (!this.field.slider_min_value) {
|
||||
this.field.slider_min_value = 0
|
||||
}
|
||||
if (!this.field.slider_max_value) {
|
||||
this.field.slider_max_value = 50
|
||||
}
|
||||
if (!this.field.slider_step_value) {
|
||||
this.field.slider_step_value = 1
|
||||
}
|
||||
}
|
||||
},
|
||||
onFieldOptionsChange (val) {
|
||||
onFieldOptionsChange(val) {
|
||||
const vals = (val) ? val.trim().split('\n') : []
|
||||
const tmpOpts = vals.map(name => {
|
||||
return {
|
||||
@@ -622,7 +473,7 @@ export default {
|
||||
})
|
||||
this.field[this.field.type] = { options: tmpOpts }
|
||||
},
|
||||
onFieldPrefillTodayChange (val) {
|
||||
onFieldPrefillTodayChange(val) {
|
||||
this.field.prefill_today = val
|
||||
if (this.field.prefill_today) {
|
||||
this.field.prefill = 'Pre-filled with current date'
|
||||
@@ -633,41 +484,78 @@ export default {
|
||||
this.field.prefill = null
|
||||
}
|
||||
},
|
||||
onFieldAllowCreationChange (val) {
|
||||
onFieldAllowCreationChange(val) {
|
||||
this.field.allow_creation = val
|
||||
if (this.field.allow_creation) {
|
||||
this.field.without_dropdown = false
|
||||
}
|
||||
},
|
||||
onFieldWithoutDropdownChange (val) {
|
||||
onFieldWithoutDropdownChange(val) {
|
||||
this.field.without_dropdown = val
|
||||
if (this.field.without_dropdown) {
|
||||
this.field.allow_creation = false
|
||||
}
|
||||
},
|
||||
onFieldDisablePastDatesChange (val) {
|
||||
onFieldDisablePastDatesChange(val) {
|
||||
this.field.disable_past_dates = val
|
||||
if (this.field.disable_past_dates) {
|
||||
this.field.disable_future_dates = false
|
||||
this.field.prefill_today = false
|
||||
}
|
||||
},
|
||||
onFieldDisableFutureDatesChange (val) {
|
||||
onFieldDisableFutureDatesChange(val) {
|
||||
this.field.disable_future_dates = val
|
||||
if (this.field.disable_future_dates) {
|
||||
this.field.disable_past_dates = false
|
||||
this.field.prefill_today = false
|
||||
}
|
||||
},
|
||||
onFieldHelpPositionChange (val) {
|
||||
onFieldHelpPositionChange(val) {
|
||||
if (!val) {
|
||||
this.field.help_position = 'below_input'
|
||||
}
|
||||
},
|
||||
selectAllCountries () {
|
||||
selectAllCountries() {
|
||||
this.field.unavailable_countries = this.allCountries.map(item => {
|
||||
return item.code
|
||||
})
|
||||
},
|
||||
setDefaultFieldValues() {
|
||||
const defaultFieldValues = {
|
||||
slider: {
|
||||
slider_min_value: 0,
|
||||
slider_max_value: 100,
|
||||
slider_step_value: 1
|
||||
},
|
||||
scale: {
|
||||
scale_min_value: 1,
|
||||
scale_max_value: 5,
|
||||
scale_step_value: 1
|
||||
},
|
||||
rating: {
|
||||
rating_max_value: 5
|
||||
},
|
||||
files: {
|
||||
max_file_size: Math.min((this.field.max_file_size ?? this.mbLimit), this.mbLimit)
|
||||
},
|
||||
text: {
|
||||
multi_lines: false,
|
||||
max_char_limit: 2000
|
||||
},
|
||||
email: {
|
||||
max_char_limit: 2000
|
||||
},
|
||||
url: {
|
||||
max_char_limit: 2000
|
||||
},
|
||||
}
|
||||
if (this.field.type in defaultFieldValues) {
|
||||
Object.keys(defaultFieldValues[this.field.type]).forEach(key => {
|
||||
if (!Object.hasOwn(this.field,key)) {
|
||||
this.field[key] = defaultFieldValues[this.field.type][key]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user