testfields.v2.ts 3.6 KB

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