Commit 4a25a1df authored by MARCO Jonathan's avatar MARCO Jonathan
Browse files

馃毀 Can use a date field to default birth date

Ref di/vue-formbuilder#58
parent 4ba7ca23
<template>
<section>
<v-switch
v-if="isHybridForm"
:input-value="isTokenField"
v-if="isHybridForm && isDefaultTokenValueField"
:input-value="linkTokenValue"
:label="_uct('builder.tabs.validation.tokenField.switchLabel')"
@change="onUpdateTokenFieldStatus"
/>
<div v-if="isTokenField">
<v-select
:items="tokenFields"
:label="_uct('builder.tabs.validation.tokenField.selectLabel')"
:value="field.defaultTokenValue"
@change="onUpdateField($event, 'defaultTokenValue')"
/>
</div>
<v-select
v-if="linkTokenValue"
:items="tokenFields"
:label="_uct('builder.tabs.validation.tokenField.selectLabel')"
:value="field.defaultTokenValue"
@change="onUpdateField($event, 'defaultTokenValue')"
/>
<v-text-field
v-else
v-else-if="!linkTokenValue && !isDateField"
:label="_uct('builder.tabs.validation.defaultValue')"
:value="field.defaultValue"
@change="onUpdateField($event, 'defaultText')"
......@@ -34,19 +33,36 @@ export default Vue.extend({
mixins: [tabValidationMixin],
data: (): { linkTokenValue: boolean } => ({
linkTokenValue: false,
}),
computed: {
...mapGetters('form', ['isHybridForm']),
...mapGetters('user', ['userStringTemplate']),
...mapGetters('formBuilder/controls', ['getControls']),
isDefaultTokenValueField(): boolean {
return this.getControls[this.field.component].usfSubtypes.includes('defaultTokenValue');
},
isTokenField(): boolean {
return has('defaultTokenValue', this.field) && this.field.defaultTokenValue !== null;
},
isDateField(): boolean {
return this.field.component === 'UsfDateTime';
},
tokenFields(): { text: string, value: string }[] {
return this.userStringTemplate.map(templateName => ({ text: templateName, value: templateName }));
},
},
mounted() {
this.linkTokenValue = this.isTokenField
},
methods: {
onUpdateTokenFieldStatus(newValue: boolean): void {
this.linkTokenValue = !this.linkTokenValue;
newValue
? this.updateField({ id: this.field.id, defaultTokenValue: '' })
: this.updateField({ id: this.field.id, defaultTokenValue: null });
......
......@@ -178,7 +178,7 @@ export const state: ControlsState = {
},
],
usfType: 'input',
usfSubtypes: ['text', 'boxInput', 'type', 'defaultValue'],
usfSubtypes: ['text', 'boxInput', 'type', 'defaultValue', 'defaultTokenValue'],
categoryColor: 'blue-grey lighten-3',
settingsModalTabs: [
modalTabs.api,
......@@ -310,7 +310,7 @@ export const state: ControlsState = {
},
],
usfType: 'input',
usfSubtypes: ['type', 'style', 'dateTime'],
usfSubtypes: ['type', 'style', 'dateTime', 'defaultValue', 'defaultTokenValue'],
categoryColor: 'blue-grey lighten-3',
settingsModalTabs: [
modalTabs.api,
......
......@@ -28,7 +28,7 @@ export interface Control {
styles?: { label: string, value: string }[];
nested?: string[];
usfType: 'layout' | 'input' | 'custom';
usfSubtypes: ('accordion' | 'boxInput' | 'dateTime' | 'defaultValue' | 'editable' | 'file' | 'grid' | 'selectElement' | 'selectable' | 'style' | 'text' | 'type' | 'withOptions')[];
usfSubtypes: ('accordion' | 'boxInput' | 'dateTime' | 'defaultTokenValue' | 'defaultValue' | 'editable' | 'file' | 'grid' | 'selectElement' | 'selectable' | 'style' | 'text' | 'type' | 'withOptions')[];
categoryColor?: string;
settingsModalTabs?: ModalTab[];
toAdd: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment