123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- // TESTS: Generation of Field-Specific Modeled MetaData using buildFieldSpecific library function
- import { ValueTransformer } from './../dynaform/interfaces';
- // ---------------------------------------------------------------------------------------------------------------------
- // Native
- const basicTextField = {
- type: 'Text',
- label: 'Field One',
- placeholder: 'Type a value here'
- };
- const styledTextField = {
- type: 'Text',
- placeholder: 'With a DOM id and CSS classes applied',
- class: ['red', 'bgPaleBlue'],
- id: 'yoyo'
- };
- const textareaField = {
- type: 'Textarea',
- placeholder: 'Type your long-winded comments here'
- };
- const passwordField = {
- type: 'Password',
- placeholder: 'It\'s a secret'
- };
- const selectField = {
- type: 'Select',
- options: ['', 'Apples', 'Oranges', 'Pears', 'Gorgonzola']
- };
- const radioField = {
- type: 'radio',
- options: ['Tea', 'Coffee', 'Cocoa', 'Yerba Maté']
- };
- const disabledTextField = {
- type: 'Text',
- placeholder: 'You can\'t touch this',
- disabled: true
- };
- const radioFieldHorizontal = {
- type: 'radio',
- options: ['Fish', 'Fowl', 'Neither'],
- horizontal: true
- };
- // ---------------------------------------------------------------------------------------------------------------------
- // Custom
- const checkbutton = {
- type: 'checkbutton',
- value: '456'
- };
- const checkbutton2 = {
- type: 'checkbutton',
- value: 'Yowsa'
- };
- const modifiers = ['Matches', 'Starts With', 'Contains'];
- const transformerFunctions: ValueTransformer = {
- inputFn: val => {
- let modifier = 'Starts With';
- if (/^%.*?%$/.test(val)) {
- modifier = 'Contains';
- } else if (/^[^%].*?[^%]$/.test(val)) {
- modifier = 'Matches';
- } else if (/^%.*/.test(val)) {
- modifier = 'Starts With';
- }
- const transformedVal = val.replace(/%/g, '').trim();
- return { modifier: modifier, value: transformedVal };
- },
- outputFn: (mod, val) => {
- let transformedValue;
- switch (mod) {
- case 'Starts With':
- transformedValue = `%${val}`;
- break;
- case 'Contains':
- transformedValue = `%${val}%`;
- break;
- case 'Matches':
- default:
- transformedValue = val;
- break;
- }
- return transformedValue;
- }
- };
- const dropdownModifiedInput = {
- type: 'dropdownModifiedInput',
- value: 'lovely',
- modifiers,
- transform: transformerFunctions
- };
- const checkbuttonGroup = {
- type: 'CheckbuttonGroup',
- firstEnablesRest: true,
- meta: { iMaskTheOthers: {}, groupMemberTwo: {}, groupMemberThree: {} }
- };
- const checkbuttonGroupArray = {
- type: 'CheckbuttonGroup',
- firstEnablesRest: false,
- showAllOrNone: true,
- meta: [
- {name: 'One', value: 111}, {name: 'Two', value: 222}, {name: 'Three', value: 333}, {name: 'Four', value: 444},
- {name: 'Five', value: 555}, {name: 'Six', value: 666}, {name: 'Seven', value: 777}, {name: 'Eight', value: 888}
- ]
- };
- // ---------------------------------------------------------------------------------------------------------------------
- // Kendo
- const timepicker = {
- type: 'timepicker'
- };
- const clrdatepicker = {
- type: 'ClrDatepicker'
- };
- // ---------------------------------------------------------------------------------------------------------------------
- // Container
- const container = {
- type: 'Container',
- meta: {
- basicTextField,
- checkbuttonGroupArray,
- }
- };
- // ---------------------------------------------------------------------------------------------------------------------
- const model = {};
- const meta = {
- basicTextField,
- styledTextField,
- textareaField,
- passwordField,
- selectField,
- radioField,
- disabledTextField,
- radioFieldHorizontal,
- checkbutton,
- dropdownModifiedInput,
- checkbuttonGroup,
- // timepicker,
- clrdatepicker,
- container
- };
- export { model, meta };
|