testfields.v2.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // ---------------------------------------------------------------------------------------------------------------------
  2. // TESTS: Generation of Field-Specific Modeled MetaData using buildFieldSpecificMeta library function
  3. // ---------------------------------------------------------------------------------------------------------------------
  4. import { ValueTransformer } from './../dynaform/interfaces';
  5. // ---------------------------------------------------------------------------------------------------------------------
  6. // Native
  7. const basicTextField = {
  8. type: 'Text',
  9. label: 'Field One',
  10. placeholder: 'Type a value here'
  11. };
  12. const styledTextField = {
  13. type: 'Text',
  14. placeholder: 'With a DOM id and CSS classes applied',
  15. class: ['red', 'bgPaleBlue'],
  16. id: 'yoyo'
  17. };
  18. const textareaField = {
  19. type: 'Textarea',
  20. placeholder: 'Type your long-winded comments here'
  21. };
  22. const passwordField = {
  23. type: 'Password',
  24. placeholder: 'It\'s a secret'
  25. };
  26. const selectField = {
  27. type: 'Select',
  28. options: ['', 'Apples', 'Oranges', 'Pears', 'Gorgonzola']
  29. };
  30. const radioField = {
  31. type: 'radio',
  32. options: ['Tea', 'Coffee', 'Cocoa', 'Yerba Maté']
  33. };
  34. const disabledTextField = {
  35. type: 'Text',
  36. placeholder: 'You can\'t touch this',
  37. disabled: true
  38. };
  39. const radioFieldHorizontal = {
  40. type: 'radio',
  41. options: ['Fish', 'Fowl', 'Neither'],
  42. horizontal: true
  43. };
  44. // ---------------------------------------------------------------------------------------------------------------------
  45. // Custom
  46. const checkbutton = {
  47. type: 'checkbutton',
  48. value: '456'
  49. };
  50. const checkbutton2 = {
  51. type: 'checkbutton',
  52. value: 'Yowsa'
  53. };
  54. const modifiers = ['Matches', 'Starts With', 'Contains'];
  55. const transformerFunctions: ValueTransformer = {
  56. inputFn: val => {
  57. let modifier = 'Starts With';
  58. if (/^%.*?%$/.test(val)) {
  59. modifier = 'Contains';
  60. } else if (/^[^%].*?[^%]$/.test(val)) {
  61. modifier = 'Matches';
  62. } else if (/^%.*/.test(val)) {
  63. modifier = 'Starts With';
  64. }
  65. const transformedVal = val.replace(/%/g, '').trim();
  66. return { modifier: modifier, value: transformedVal };
  67. },
  68. outputFn: (mod, val) => {
  69. let transformedValue;
  70. switch (mod) {
  71. case 'Starts With':
  72. transformedValue = `%${val}`;
  73. break;
  74. case 'Contains':
  75. transformedValue = `%${val}%`;
  76. break;
  77. case 'Matches':
  78. default:
  79. transformedValue = val;
  80. break;
  81. }
  82. return transformedValue;
  83. }
  84. };
  85. const dropdownModifiedInput = {
  86. type: 'dropdownModifiedInput',
  87. value: 'lovely',
  88. modifiers,
  89. transform: transformerFunctions
  90. };
  91. const checkbuttonGroup = {
  92. type: 'CheckbuttonGroup',
  93. firstEnablesRest: true,
  94. meta: { iMaskTheOthers: {}, groupMemberTwo: {}, groupMemberThree: {} }
  95. };
  96. const checkbuttonGroupArray = {
  97. type: 'CheckbuttonGroup',
  98. firstEnablesRest: false,
  99. showAllOrNone: true,
  100. meta: [
  101. {name: 'One', value: 111}, {name: 'Two', value: 222}, {name: 'Three', value: 333}, {name: 'Four', value: 444},
  102. {name: 'Five', value: 555}, {name: 'Six', value: 666}, {name: 'Seven', value: 777}, {name: 'Eight', value: 888}
  103. ]
  104. };
  105. // ---------------------------------------------------------------------------------------------------------------------
  106. // Kendo
  107. const timepicker = {
  108. type: 'timepicker'
  109. };
  110. const datepicker = {
  111. type: 'datepicker'
  112. };
  113. // ---------------------------------------------------------------------------------------------------------------------
  114. // Container
  115. const container = {
  116. type: 'Container',
  117. meta: {
  118. basicTextField,
  119. checkbuttonGroupArray,
  120. }
  121. };
  122. // ---------------------------------------------------------------------------------------------------------------------
  123. const model = {};
  124. const meta = {
  125. basicTextField,
  126. styledTextField,
  127. textareaField,
  128. passwordField,
  129. selectField,
  130. radioField,
  131. disabledTextField,
  132. radioFieldHorizontal,
  133. checkbutton,
  134. dropdownModifiedInput,
  135. checkbuttonGroup,
  136. timepicker,
  137. datepicker,
  138. container
  139. };
  140. export { model, meta };