Allow use of toggle switches for checkboxes (#13)
This commit is contained in:
parent
bd7d20feb9
commit
545908d300
|
@ -84,6 +84,7 @@ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
|
||||||
'properties.*.timezone' => 'sometimes|nullable',
|
'properties.*.timezone' => 'sometimes|nullable',
|
||||||
'properties.*.width' => ['sometimes', Rule::in(['full','1/2','1/3','2/3','1/3','3/4','1/4'])],
|
'properties.*.width' => ['sometimes', Rule::in(['full','1/2','1/3','2/3','1/3','3/4','1/4'])],
|
||||||
'properties.*.allowed_file_types' => 'sometimes|nullable',
|
'properties.*.allowed_file_types' => 'sometimes|nullable',
|
||||||
|
'properties.*.use_toggle_switch' => 'boolean|nullable',
|
||||||
|
|
||||||
// Logic
|
// Logic
|
||||||
'properties.*.logic' => ['array', 'nullable', new FormPropertyLogicRule()],
|
'properties.*.logic' => ['array', 'nullable', new FormPropertyLogicRule()],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="wrapperClass">
|
<div :class="wrapperClass">
|
||||||
<v-checkbox :id="id?id:name" v-model="compVal" :disabled="disabled" :name="name" @input="$emit('input',$event)">
|
<v-checkbox :id="id?id:name" v-model="compVal" :disabled="disabled" :name="name" @input="$emit('input',$event)">
|
||||||
{{ label }}
|
{{ label }} <span v-if="required" class="text-red-500 required-dot">*</span>
|
||||||
</v-checkbox>
|
</v-checkbox>
|
||||||
<small v-if="help" :class="theme.default.help">
|
<small v-if="help" :class="theme.default.help">
|
||||||
<slot name="help">{{ help }}</slot>
|
<slot name="help">{{ help }}</slot>
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
{{ label }}
|
{{ label }}
|
||||||
<span v-if="required" class="text-red-500 required-dot">*</span>
|
<span v-if="required" class="text-red-500 required-dot">*</span>
|
||||||
</label>
|
</label>
|
||||||
|
<small v-if="help" :class="theme.SelectInput.help" class="block mb-2">
|
||||||
|
<slot name="help">{{ 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]"
|
<div v-for="(option, index) in options" v-else :key="option[optionKey]"
|
||||||
|
@ -22,9 +25,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<small v-if="help" :class="theme.SelectInput.help">
|
|
||||||
<slot name="help">{{ help }}</slot>
|
|
||||||
</small>
|
|
||||||
<has-error v-if="hasValidation" :form="form" :field="name" />
|
<has-error v-if="hasValidation" :form="form" :field="name" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<template>
|
||||||
|
<div :class="wrapperClass">
|
||||||
|
<div class="flex">
|
||||||
|
<v-switch :id="id?id:name" v-model="compVal" class="inline-block mr-2" :disabled="disabled" :name="name" @input="$emit('input',$event)" />
|
||||||
|
<span>{{ label }} <span v-if="required" class="text-red-500 required-dot">*</span></span>
|
||||||
|
</div>
|
||||||
|
<small v-if="help" :class="theme.default.help">
|
||||||
|
<slot name="help">{{ help }}</slot>
|
||||||
|
</small>
|
||||||
|
<has-error v-if="hasValidation" :form="form" :field="name" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import inputMixin from '~/mixins/forms/input'
|
||||||
|
|
||||||
|
import VSwitch from './components/VSwitch'
|
||||||
|
export default {
|
||||||
|
name: 'ToggleSwitchInput',
|
||||||
|
|
||||||
|
components: { VSwitch },
|
||||||
|
mixins: [inputMixin],
|
||||||
|
props: {},
|
||||||
|
|
||||||
|
mounted () {
|
||||||
|
this.compVal = !!this.compVal
|
||||||
|
this.$emit('input', !!this.compVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
|
@ -16,6 +16,7 @@ import ImageInput from './ImageInput'
|
||||||
import DateInput from './DateInput';
|
import DateInput from './DateInput';
|
||||||
import RatingInput from './RatingInput';
|
import RatingInput from './RatingInput';
|
||||||
import FlatSelectInput from './FlatSelectInput';
|
import FlatSelectInput from './FlatSelectInput';
|
||||||
|
import ToggleSwitchInput from './ToggleSwitchInput';
|
||||||
|
|
||||||
// Components that are registered globaly.
|
// Components that are registered globaly.
|
||||||
[
|
[
|
||||||
|
@ -34,7 +35,8 @@ import FlatSelectInput from './FlatSelectInput';
|
||||||
RichTextAreaInput,
|
RichTextAreaInput,
|
||||||
DateInput,
|
DateInput,
|
||||||
RatingInput,
|
RatingInput,
|
||||||
FlatSelectInput
|
FlatSelectInput,
|
||||||
|
ToggleSwitchInput
|
||||||
].forEach(Component => {
|
].forEach(Component => {
|
||||||
Vue.component(Component.name, Component)
|
Vue.component(Component.name, Component)
|
||||||
})
|
})
|
||||||
|
|
|
@ -317,6 +317,9 @@ export default {
|
||||||
if (['select', 'multi_select'].includes(field.type) && field.without_dropdown) {
|
if (['select', 'multi_select'].includes(field.type) && field.without_dropdown) {
|
||||||
return 'FlatSelectInput'
|
return 'FlatSelectInput'
|
||||||
}
|
}
|
||||||
|
if (field.type === 'checkbox' && field.use_toggle_switch) {
|
||||||
|
return 'ToggleSwitchInput'
|
||||||
|
}
|
||||||
return this.fieldComponents[field.type]
|
return this.fieldComponents[field.type]
|
||||||
},
|
},
|
||||||
getFieldClasses (field) {
|
getFieldClasses (field) {
|
||||||
|
|
|
@ -37,6 +37,24 @@
|
||||||
</v-checkbox>
|
</v-checkbox>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Checkbox -->
|
||||||
|
<div v-if="field.type === 'checkbox'" class="-mx-4 sm:-mx-6 p-5 border-b">
|
||||||
|
<h3 class="font-semibold block text-lg">
|
||||||
|
Checkbox
|
||||||
|
</h3>
|
||||||
|
<p class="text-gray-400 mb-5">
|
||||||
|
Advanced options for checkbox.
|
||||||
|
</p>
|
||||||
|
<v-checkbox v-model="field.use_toggle_switch" class="mt-4"
|
||||||
|
name="use_toggle_switch" help=""
|
||||||
|
>
|
||||||
|
Use toggle switch
|
||||||
|
</v-checkbox>
|
||||||
|
<p class="text-gray-400 mb-5">
|
||||||
|
If enabled, checkbox will be replaced with a toggle switch
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- File Uploads -->
|
<!-- File Uploads -->
|
||||||
<div v-if="field.type === 'files'" class="-mx-4 sm:-mx-6 p-5 border-b">
|
<div v-if="field.type === 'files'" class="-mx-4 sm:-mx-6 p-5 border-b">
|
||||||
<h3 class="font-semibold block text-lg">
|
<h3 class="font-semibold block text-lg">
|
||||||
|
|
Loading…
Reference in New Issue