All files / src/components/FormField/mixins fieldMap.ts

100% Statements 18/18
100% Branches 3/3
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 536x 6x               6x 6x 6x 6x 6x 6x 6x                           26x   26x                                 6x 25x   6x  
import Vue from 'vue';
import Component from 'vue-class-component';
 
export interface IFieldMap {
	[key: string]: string;
}
 
// We import them all because the form
// can use any of them
import DateField from '../fields/DateField.vue';
import NumberField from '../fields/NumberField.vue';
import PasswordField from '../fields/PasswordField.vue';
import PeriodField from '../fields/PeriodField.vue';
import ChoiceField from '../fields/ChoiceField.vue';
import TextareaField from '../fields/TextareaField.vue';
import TextField from '../fields/TextField.vue';
 
/** List all fields and provide getField() function */
@Component({
	components: {
		DateField,
		NumberField,
		PasswordField,
		PeriodField,
		ChoiceField,
		TextareaField,
		TextField
	}
})
export class FieldMap extends Vue {
	/** List all field components and their corresponding keys */
	fieldMap: IFieldMap = {
		date: 'DateField',
		number: 'NumberField',
		password: 'PasswordField',
		period: 'PeriodField',
		select: 'ChoiceField',
		text: 'TextField',
		textarea: 'TextareaField'
	};
 
	/**
	 * Returns the field that correspond to the name
	 * passed in argument
	 *
	 * @param {string} fieldName The name of the field
	 * @returns {string} The field
	 */
	getField(fieldName: string): string {
		return this.fieldMap[fieldName];
	}
}