form.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839
  1. // form
  2. QUnit.test("form without @el", assert => {
  3. var form = new App.ControllerForm()
  4. assert.equal($(form.html()).is('div'), true)
  5. assert.equal($(form.html()).hasClass('alert'), true)
  6. assert.equal($(form.html()).hasClass('hide'), true)
  7. })
  8. QUnit.test("form elements check", assert => {
  9. // assert.deepEqual(item, test.value, 'group set/get tests' );
  10. $('#qunit').append('<hr><h1>form elements check</h1><form id="form1"></form>')
  11. var el = $('#form1')
  12. var defaults = {
  13. input2: '123abc',
  14. password2: 'pw1234<l>',
  15. textarea2: 'lalu <l> lalu',
  16. select1: false,
  17. select2: true,
  18. selectmulti1: [ false ],
  19. selectmulti2: [ false, true ],
  20. selectmultioption1: [ false ],
  21. selectmultioption2: [ false, true ],
  22. richtext2: 'lalu <l> lalu',
  23. datetime1: Date.parse('2015-01-11T12:40:00Z'),
  24. checkbox1: [],
  25. checkbox2: '1',
  26. boolean1: true,
  27. boolean2: false,
  28. switch1: true,
  29. switch2: false,
  30. }
  31. new App.ControllerForm({
  32. el: el,
  33. model: {
  34. configure_attributes: [
  35. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: defaults['input1'] },
  36. { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['input2'] },
  37. { name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: true, default: defaults['password1'] },
  38. { name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false, default: defaults['password2'] },
  39. { name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: true, upload: true, default: defaults['textarea1'] },
  40. { name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: defaults['textarea2'] },
  41. { name: 'textarea3', display: 'Textarea3', tag: 'textarea', limit: 100, null: false, upload: true, default: defaults['textarea3'] },
  42. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: defaults['select1'] },
  43. { name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' }, default: defaults['select2'] },
  44. { name: 'selectmulti1', display: 'SelectMulti1', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti1'] },
  45. { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti2'] },
  46. { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: defaults['selectmultioption1'] },
  47. { name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }], default: defaults['selectmultioption2'] },
  48. { name: 'richtext1', display: 'Richtext1', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext1'] },
  49. { name: 'richtext2', display: 'Richtext2', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext2'] },
  50. { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
  51. { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] },
  52. { name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
  53. { name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
  54. { name: 'boolean1', display: 'Boolean1', tag: 'boolean', null: false, default: defaults['boolean1'] },
  55. { name: 'boolean2', display: 'Boolean2', tag: 'boolean', null: false, default: defaults['boolean2'] },
  56. { name: 'boolean3', display: 'Boolean3', tag: 'boolean', null: false, default: defaults['boolean3'] },
  57. { name: 'switch1', display: 'Switch1', tag: 'switch', null: false, default: defaults['switch1'] },
  58. { name: 'switch2', display: 'Switch2', tag: 'switch', null: false, default: defaults['switch2'] },
  59. { name: 'switch3', display: 'Switch3', tag: 'switch', null: false, default: defaults['switch3'] },
  60. ]
  61. },
  62. autofocus: true
  63. });
  64. assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
  65. assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
  66. // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
  67. assert.equal(el.find('[name="input2"]').val(), '123abc', 'check input2 value')
  68. assert.equal(el.find('[name="input2"]').prop('required'), true, 'check input2 required')
  69. assert.equal(el.find('[name="input2"]').is(":focus"), false, 'check input2 focus')
  70. assert.equal(el.find('[name="password1"]').val(), '', 'check password1 value')
  71. assert.equal(el.find('[name="password1_confirm"]').val(), '', 'check password1 value')
  72. assert.equal(el.find('[name="password1"]').prop('required'), false, 'check password1 required')
  73. assert.equal(el.find('[name="password1"]').is(":focus"), false, 'check password1 focus')
  74. assert.equal(el.find('[name="password2"]').val(), 'pw1234<l>', 'check password2 value')
  75. assert.equal(el.find('[name="password2_confirm"]').val(), 'pw1234<l>', 'check password2 value')
  76. assert.equal(el.find('[name="password2"]').prop('required'), true, 'check password2 required')
  77. assert.equal(el.find('[name="password2"]').is(":focus"), false, 'check password2 focus')
  78. assert.equal(el.find('[name="textarea1"]').val(), '', 'check textarea1 value')
  79. assert.equal(el.find('[name="textarea1"]').prop('required'), false, 'check textarea1 required')
  80. assert.equal(el.find('[name="textarea1"]').is(":focus"), false, 'check textarea1 focus')
  81. assert.equal(el.find('[name="textarea2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
  82. assert.equal(el.find('[name="textarea2"]').prop('required'), true, 'check textarea2 required')
  83. assert.equal(el.find('[name="textarea2"]').is(":focus"), false, 'check textarea2 focus')
  84. assert.equal(el.find('[name="textarea2"]').prop("rows"), 6, 'check textarea2 rows')
  85. assert.equal(el.find('[name="textarea3"]').prop("rows"), 4, 'check textarea3 rows (default value)')
  86. assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
  87. assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
  88. assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
  89. assert.equal(el.find('[name="select2"]').val(), 'true', 'check select2 value')
  90. assert.equal(el.find('[name="select2"]').prop('required'), true, 'check select2 required')
  91. assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
  92. assert.equal(el.find('[name="selectmulti1"]').val(), 'false', 'check selectmulti1 value')
  93. assert.equal(el.find('[name="selectmulti1"]').prop('required'), false, 'check selectmulti1 required')
  94. assert.equal(el.find('[name="selectmulti1"]').is(":focus"), false, 'check selectmulti1 focus')
  95. assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
  96. assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
  97. assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
  98. assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
  99. //equal(el.find('[name="richtext1"]').val(), '', 'check textarea1 value')
  100. //equal(el.find('[name="richtext1"]').prop('required'), false, 'check textarea1 required')
  101. assert.equal(el.find('[name="richtext1"]').is(":focus"), false, 'check textarea1 focus')
  102. //equal(el.find('[name="richtext2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
  103. //equal(el.find('[name="richtext2"]').prop('required'), true, 'check textarea2 required')
  104. assert.equal(el.find('[name="richtext2"]').is(":focus"), false, 'check textarea2 focus')
  105. assert.equal(el.find('[name="checkbox1"]').first().is(":checked"), false)
  106. assert.equal(el.find('[name="checkbox1"]').last().is(":checked"), false)
  107. assert.equal(el.find('[name="checkbox2"]').is(":checked"), true)
  108. assert.equal(el.find('[name="boolean1"]').val(), 'true')
  109. assert.equal(el.find('[name="boolean1"]').val(), 'true')
  110. assert.equal(el.find('[name="boolean2"]').val(), 'false')
  111. assert.equal(el.find('[name="switch1"]').is(':checked'), true)
  112. assert.equal(el.find('[name="switch2"]').is(':checked'), false)
  113. assert.equal(el.find('[name="switch3"]').is(':checked'), false)
  114. });
  115. QUnit.test("form params check 1", assert => {
  116. // assert.deepEqual(item, test.value, 'group set/get tests' );
  117. $('#qunit').append('<hr><h1>form params check</h1><form id="form2"></form>')
  118. var el = $('#form2')
  119. var defaults = {
  120. input2: '123abc',
  121. password2: 'pw1234<l>',
  122. textarea2: 'lalu <l> lalu',
  123. select1: false,
  124. select2: true,
  125. select3: null,
  126. select4: undefined,
  127. select5: false,
  128. selectmulti1: [ false ],
  129. selectmulti2: [ false, true ],
  130. selectmulti3: [ false ],
  131. selectmultioption1: [ false ],
  132. selectmultioption2: [ false, true ],
  133. selectmultioption2: [ false, true ],
  134. selectmultioption3: [ false ],
  135. autocompletion2: 'id2',
  136. autocompletion2_autocompletion_value_shown: 'value2',
  137. richtext2: '<div>lalu <b>b</b> lalu</div>',
  138. richtext3: '<div></div>',
  139. richtext4: '<div>lalu <i>b</i> lalu</div>',
  140. richtext5: '<div></div>',
  141. richtext6: '<div>lalu <b>b</b> lalu</div>',
  142. richtext7: "<div>&nbsp;<div>&nbsp;\n</div> \n</div>",
  143. richtext8: '<div>lalu <i>b</i> lalu</div>',
  144. richtext9: '<div>lalu <b>b</b> lalu</div>',
  145. datetime1: new Date(Date.parse('2015-01-11T12:40:00Z') ),
  146. datetime3: new Date(Date.parse('2015-01-11T12:40:00Z') ),
  147. datetime5: new Date(Date.parse('2015-01-11T12:40:00Z') ),
  148. date1: '2015-01-11',
  149. date3: '2015-01-11',
  150. date5: '2015-01-11',
  151. active1: true,
  152. active2: false,
  153. checkbox1: [],
  154. checkbox2: undefined,
  155. checkbox3: 'd',
  156. checkbox5: 'd',
  157. radiobox1: undefined,
  158. radiobox2: 'a',
  159. radiobox3: 'a',
  160. boolean1: true,
  161. boolean2: false,
  162. boolean4: false,
  163. switch1: true,
  164. switch2: false,
  165. switch4: true,
  166. }
  167. new App.ControllerForm({
  168. el: el,
  169. model: {
  170. configure_attributes: [
  171. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true },
  172. { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: false },
  173. { name: 'input3', display: 'Input3', tag: 'input', type: 'text', limit: 100, null: true, disabled: true },
  174. { name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: true },
  175. { name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false },
  176. { name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: true, upload: true },
  177. { name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true },
  178. { name: 'textarea3', display: 'Textarea3', tag: 'textarea', rows: 6, limit: 100, null: true, upload: false, disabled: true },
  179. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' } },
  180. { name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' } },
  181. { name: 'select3', display: 'Select3', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select3' } },
  182. { name: 'select4', display: 'Select4', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select4' } },
  183. { name: 'select5', display: 'Select5', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, disabled: true },
  184. { name: 'selectmulti1', display: 'SelectMulti1', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' } },
  185. { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' } },
  186. { name: 'selectmulti3', display: 'SelectMulti3', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' }, disabled: true },
  187. { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }] },
  188. { name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }] },
  189. { name: 'selectmultioption3', display: 'SelectMultiOption3', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], disabled: true },
  190. { name: 'autocompletion1', display: 'AutoCompletion1', tag: 'autocompletion', null: false, options: { true: 'internal', false: 'public' }, source: [ { label: "Choice1", value: "value1", id: "id1" }, { label: "Choice2", value: "value2", id: "id2" }, ], minLength: 1 },
  191. { name: 'autocompletion2', display: 'AutoCompletion2', tag: 'autocompletion', null: false, options: { true: 'internal', false: 'public' }, source: [ { label: "Choice1", value: "value1", id: "id1" }, { label: "Choice2", value: "value2", id: "id2" }, ], minLength: 1 },
  192. { name: 'richtext1', display: 'Richtext1', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext1'] },
  193. { name: 'richtext2', display: 'Richtext2', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext2'] },
  194. { name: 'richtext3', display: 'Richtext3', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext3'] },
  195. { name: 'richtext4', display: 'Richtext4', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext4'] },
  196. { name: 'richtext5', display: 'Richtext5', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext5'] },
  197. { name: 'richtext6', display: 'Richtext6', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext6'] },
  198. { name: 'richtext7', display: 'Richtext7', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext7'] },
  199. { name: 'richtext8', display: 'Richtext8', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext8'] },
  200. { name: 'richtext9', display: 'Richtext9', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext9'], disabled: true},
  201. { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
  202. { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, default: defaults['datetime2'] },
  203. { name: 'datetime3', display: 'Datetime3', tag: 'datetime', null: false, default: defaults['datetime3'] },
  204. { name: 'datetime4', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime4'] },
  205. { name: 'datetime5', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime5'], disabled: true },
  206. { name: 'date1', display: 'Date1', tag: 'date', null: true, default: defaults['date1'] },
  207. { name: 'date2', display: 'Date2', tag: 'date', null: true, default: defaults['date2'] },
  208. { name: 'date3', display: 'Date3', tag: 'date', null: false, default: defaults['date3'] },
  209. { name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
  210. { name: 'date5', display: 'Date4', tag: 'date', null: false, default: defaults['date5'], disabled: true },
  211. { name: 'active1', display: 'Active1', tag: 'active', default: defaults['active1'] },
  212. { name: 'active2', display: 'Active2', tag: 'active', default: defaults['active2'] },
  213. { name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
  214. { name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
  215. { name: 'checkbox3', display: 'Checkbox3', tag: 'checkbox', null: false, default: defaults['checkbox3'], options: { c: 'CC', d: 'DD' } },
  216. { name: 'checkbox4', display: 'Checkbox4', tag: 'checkbox', null: false, default: defaults['checkbox4'], options: { aa: 'AA', bb: 'BB' } },
  217. { name: 'checkbox5', display: 'Checkbox5', tag: 'checkbox', null: false, default: defaults['checkbox5'], options: { c: 'CC', d: 'DD' }, disabled: true },
  218. { name: 'radiobox1', display: 'Radiobox1', tag: 'radio', null: false, default: defaults['radiobox1'], options: { a: 'AA', b: 'BB' } },
  219. { name: 'radiobox2', display: 'Radiobox2', tag: 'radio', null: false, default: defaults['radiobox2'], options: { a: '11' } },
  220. { name: 'radiobox3', display: 'Radiobox3', tag: 'radio', null: false, default: defaults['radiobox3'], options: { a: 'AA', b: 'BB' }, disabled: true },
  221. { name: 'boolean1', display: 'Boolean1', tag: 'boolean', null: false, default: defaults['boolean1'] },
  222. { name: 'boolean2', display: 'Boolean2', tag: 'boolean', null: false, default: defaults['boolean2'] },
  223. { name: 'boolean3', display: 'Boolean3', tag: 'boolean', null: false, default: defaults['boolean3'] },
  224. { name: 'boolean4', display: 'Boolean4', tag: 'boolean', null: false, default: defaults['boolean4'], disabled: true },
  225. { name: 'switch1', display: 'Switch1', tag: 'switch', null: false, default: defaults['switch1'] },
  226. { name: 'switch2', display: 'Switch2', tag: 'switch', null: false, default: defaults['switch2'] },
  227. { name: 'switch3', display: 'Switch3', tag: 'switch', null: false, default: defaults['switch3'] },
  228. { name: 'switch4', display: 'Switch4', tag: 'switch', null: false, default: defaults['switch4'], disabled: true },
  229. ],
  230. },
  231. params: defaults,
  232. autofocus: true
  233. });
  234. assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
  235. assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
  236. // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
  237. assert.equal(el.find('[name="input2"]').val(), '123abc', 'check input2 value')
  238. assert.equal(el.find('[name="input2"]').prop('required'), true, 'check input2 required')
  239. assert.equal(el.find('[name="input2"]').is(":focus"), false, 'check input2 focus')
  240. assert.equal(el.find('[name="input3"]').prop("disabled"), true, 'check input3 disabled')
  241. assert.equal(el.find('[name="password1"]').val(), '', 'check password1 value')
  242. assert.equal(el.find('[name="password1_confirm"]').val(), '', 'check password1 value')
  243. assert.equal(el.find('[name="password1"]').prop('required'), false, 'check password1 required')
  244. assert.equal(el.find('[name="password1"]').is(":focus"), false, 'check password1 focus')
  245. assert.equal(el.find('[name="password2"]').val(), 'pw1234<l>', 'check password2 value')
  246. assert.equal(el.find('[name="password2_confirm"]').val(), 'pw1234<l>', 'check password2 value')
  247. assert.equal(el.find('[name="password2"]').prop('required'), true, 'check password2 required')
  248. assert.equal(el.find('[name="password2"]').is(":focus"), false, 'check password2 focus')
  249. assert.equal(el.find('[name="textarea1"]').val(), '', 'check textarea1 value')
  250. assert.equal(el.find('[name="textarea1"]').prop('required'), false, 'check textarea1 required')
  251. assert.equal(el.find('[name="textarea1"]').is(":focus"), false, 'check textarea1 focus')
  252. assert.equal(el.find('[name="textarea2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
  253. assert.equal(el.find('[name="textarea2"]').prop('required'), true, 'check textarea2 required')
  254. assert.equal(el.find('[name="textarea2"]').is(":focus"), false, 'check textarea2 focus')
  255. assert.equal(el.find('[name="textarea3"]').prop("disabled"), true, 'check textarea3 disabled')
  256. assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
  257. assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
  258. assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
  259. assert.equal(el.find('[name="select2"]').val(), 'true', 'check select2 value')
  260. assert.equal(el.find('[name="select2"]').prop('required'), true, 'check select2 required')
  261. assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
  262. assert.equal(el.find('[name="select3"]').val(), '', 'check select3 value')
  263. assert.equal(el.find('[name="select3"]').prop('required'), true, 'check select3 required')
  264. assert.equal(el.find('[name="select3"]').is(":focus"), false, 'check select3 focus')
  265. assert.equal(el.find('[name="select4"]').val(), '', 'check select4 value')
  266. assert.equal(el.find('[name="select4"]').prop('required'), true, 'check select4 required')
  267. assert.equal(el.find('[name="select4"]').is(":focus"), false, 'check select4 focus')
  268. assert.equal(el.find('[name="select5"]').prop("disabled"), true, 'check select5 disabled')
  269. assert.equal(el.find('[name="selectmulti1"]').val(), 'false', 'check selectmulti1 value')
  270. assert.equal(el.find('[name="selectmulti1"]').prop('required'), false, 'check selectmulti1 required')
  271. assert.equal(el.find('[name="selectmulti1"]').is(":focus"), false, 'check selectmulti1 focus')
  272. assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
  273. assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
  274. assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
  275. assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
  276. assert.equal(el.find('[name="selectmulti3"]').prop("disabled"), true, 'check selectmulti3 disabled')
  277. assert.equal(el.find('[name="selectmultioption3"]').prop("disabled"), true, 'check selectmultioption3 disabled')
  278. assert.equal(el.find('[name="boolean4"]').prop("disabled"), true, 'check boolean4 disabled')
  279. assert.equal(el.find('[data-name="richtext9"]').prop("contenteditable"), "false", 'check richtext9 disabled')
  280. assert.equal(el.find('[name="checkbox5"]').prop("disabled"), true, 'check checkbox5 disabled')
  281. assert.equal(el.find('[name="radiobox3"]').prop("disabled"), true, 'check radiobox3 disabled')
  282. assert.equal(el.find('[name="switch4"]').prop("disabled"), true, 'check switch4 disabled')
  283. params = App.ControllerForm.params(el)
  284. test_params = {
  285. input1: '',
  286. input2: '123abc',
  287. input3: '',
  288. password1: '',
  289. password1_confirm: '',
  290. password2: 'pw1234<l>',
  291. password2_confirm: 'pw1234<l>',
  292. textarea1: '',
  293. textarea2: 'lalu <l> lalu',
  294. textarea3: '',
  295. select1: 'false',
  296. select2: 'true',
  297. select3: '',
  298. select4: '',
  299. select5: 'false',
  300. selectmulti1: [ 'false' ],
  301. selectmulti2: [ 'true', 'false' ],
  302. selectmulti3: [ 'false' ],
  303. selectmultioption1: [ 'false' ],
  304. selectmultioption2: [ 'true', 'false' ],
  305. selectmultioption3: [ 'false' ],
  306. autocompletion1: '',
  307. autocompletion1_autocompletion: '',
  308. autocompletion1_autocompletion_value_shown: '',
  309. autocompletion2: 'id2',
  310. autocompletion2_autocompletion: 'value2',
  311. autocompletion2_autocompletion_value_shown: 'value2',
  312. richtext1: '',
  313. richtext2: '<div>lalu <b>b</b> lalu</div>',
  314. richtext3: '',
  315. richtext4: '<div>lalu <i>b</i> lalu</div>',
  316. richtext5: '',
  317. richtext6: '<div>lalu <b>b</b> lalu</div>',
  318. richtext7: '',
  319. richtext8: '<div>lalu <i>b</i> lalu</div>',
  320. richtext9: '<div>lalu <b>b</b> lalu</div>',
  321. datetime1: '2015-01-11T12:40:00.000Z',
  322. datetime2: null,
  323. datetime3: '2015-01-11T12:40:00.000Z',
  324. datetime4: null,
  325. datetime5: '2015-01-11T12:40:00.000Z',
  326. date1: '2015-01-11',
  327. date2: null,
  328. date3: '2015-01-11',
  329. date4: null,
  330. date5: '2015-01-11',
  331. active1: true,
  332. active2: false,
  333. checkbox1: [],
  334. checkbox2: undefined,
  335. checkbox3: 'd',
  336. checkbox4: [],
  337. checkbox5: 'd',
  338. radiobox1: undefined,
  339. radiobox2: 'a',
  340. radiobox3: 'a',
  341. boolean1: true,
  342. boolean2: false,
  343. boolean3: true,
  344. boolean4: false,
  345. switch1: true,
  346. switch2: false,
  347. switch3: false,
  348. switch4: true,
  349. }
  350. assert.deepEqual(params, test_params, 'form param check 1')
  351. });
  352. QUnit.test("form defaults + params check", assert => {
  353. // assert.deepEqual(item, test.value, 'group set/get tests' );
  354. // mix default and params -> check it -> add note
  355. // test auto completion
  356. // show/hide fields base on field values -> bind changed event
  357. // form validation
  358. // form params check
  359. // add signature only if form_state is empty
  360. $('#qunit').append('<hr><h1>form defaults + params check</h1><form id="form3"></form>')
  361. var el = $('#form3')
  362. var defaults = {
  363. input1: '',
  364. password2: 'pw1234<l>',
  365. textarea2: 'lalu <l> lalu',
  366. select2: false,
  367. selectmulti2: [ false, true ],
  368. selectmultioption1: false,
  369. }
  370. new App.ControllerForm({
  371. el: el,
  372. model: {
  373. configure_attributes: [
  374. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' },
  375. { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
  376. { name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: false, default: 'some used pass' },
  377. { name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false, default: 'some not used pass' },
  378. { name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: 'some used text' },
  379. { name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: 'some not used text' },
  380. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: false},
  381. { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: true },
  382. { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: [] },
  383. { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: true },
  384. ],
  385. },
  386. params: defaults,
  387. autofocus: true
  388. });
  389. assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
  390. assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
  391. // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
  392. assert.equal(el.find('[name="input2"]').val(), 'some used default', 'check input2 value')
  393. assert.equal(el.find('[name="input2"]').prop('required'), false, 'check input2 required')
  394. assert.equal(el.find('[name="password1"]').val(), 'some used pass', 'check password1 value')
  395. assert.equal(el.find('[name="password1_confirm"]').val(), 'some used pass', 'check password1 value')
  396. assert.equal(el.find('[name="password1"]').prop('required'), true, 'check password1 required')
  397. assert.equal(el.find('[name="password1"]').is(":focus"), false, 'check password1 focus')
  398. assert.equal(el.find('[name="password2"]').val(), 'pw1234<l>', 'check password2 value')
  399. assert.equal(el.find('[name="password2_confirm"]').val(), 'pw1234<l>', 'check password2 value')
  400. assert.equal(el.find('[name="password2"]').prop('required'), true, 'check password2 required')
  401. assert.equal(el.find('[name="password2"]').is(":focus"), false, 'check password2 focus')
  402. assert.equal(el.find('[name="textarea1"]').val(), 'some used text', 'check textarea1 value')
  403. assert.equal(el.find('[name="textarea1"]').prop('required'), true, 'check textarea1 required')
  404. assert.equal(el.find('[name="textarea1"]').is(":focus"), false, 'check textarea1 focus')
  405. assert.equal(el.find('[name="textarea2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
  406. assert.equal(el.find('[name="textarea2"]').prop('required'), true, 'check textarea2 required')
  407. assert.equal(el.find('[name="textarea2"]').is(":focus"), false, 'check textarea2 focus')
  408. assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
  409. assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
  410. assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
  411. assert.equal(el.find('[name="select2"]').val(), 'false', 'check select2 value')
  412. assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
  413. assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
  414. assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
  415. assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
  416. assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
  417. assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
  418. });
  419. QUnit.test("form dependend fields check", assert => {
  420. // assert.deepEqual(item, test.value, 'group set/get tests' );
  421. // mix default and params -> check it -> add note
  422. // test auto completion
  423. // show/hide fields base on field values -> bind changed event
  424. // form validation
  425. // form params check
  426. // add signature only if form_state is empty
  427. $('#qunit').append('<hr><h1>form dependend fields check</h1><form id="form4"></form>')
  428. var el = $('#form4')
  429. var defaults = {
  430. input1: '',
  431. select2: false,
  432. selectmulti2: [ false, true ],
  433. selectmultioption1: false,
  434. datetime1: new Date(Date.parse('2015-01-11T12:40:00Z')),
  435. datetime3: new Date(Date.parse('2015-01-11T12:40:00Z')),
  436. date1: '2015-01-11',
  437. date3: '2015-01-11',
  438. }
  439. var form = new App.ControllerForm({
  440. el: el,
  441. model: {
  442. configure_attributes: [
  443. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' },
  444. { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
  445. { name: 'input3', display: 'Input3', tag: 'input', type: 'text', limit: 100, null: true, hide: true, default: 'some used default' },
  446. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: false},
  447. { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: true },
  448. { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: [] },
  449. { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: true },
  450. { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
  451. { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, default: defaults['datetime2'] },
  452. { name: 'datetime3', display: 'Datetime3', tag: 'datetime', null: false, default: defaults['datetime3'] },
  453. { name: 'datetime4', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime4'] },
  454. { name: 'date1', display: 'Date1', tag: 'date', null: true, default: defaults['date1'] },
  455. { name: 'date2', display: 'Date2', tag: 'date', null: true, default: defaults['date2'] },
  456. { name: 'date3', display: 'Date3', tag: 'date', null: false, default: defaults['date3'] },
  457. { name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
  458. ],
  459. },
  460. params: defaults,
  461. dependency: [
  462. {
  463. bind: {
  464. name: 'select1',
  465. value: ["true"]
  466. },
  467. change: {
  468. name: 'input2',
  469. action: 'hide'
  470. },
  471. },
  472. {
  473. bind: {
  474. name: 'select1',
  475. value: ["true"]
  476. },
  477. change: {
  478. name: 'datetime1',
  479. action: 'hide'
  480. },
  481. },
  482. {
  483. bind: {
  484. name: 'select1',
  485. value: ["false"]
  486. },
  487. change: {
  488. name: 'input2',
  489. action: 'show'
  490. },
  491. },
  492. {
  493. bind: {
  494. name: 'select1',
  495. value: ["false"]
  496. },
  497. change: {
  498. name: 'datetime1',
  499. action: 'show'
  500. },
  501. },
  502. {
  503. bind: {
  504. name: 'select1',
  505. value: ["true"]
  506. },
  507. change: {
  508. name: 'input3',
  509. action: 'show'
  510. },
  511. },
  512. {
  513. bind: {
  514. name: 'select1',
  515. value: ["false"]
  516. },
  517. change: {
  518. name: 'input3',
  519. action: 'hide'
  520. },
  521. }
  522. ],
  523. autofocus: true
  524. });
  525. assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
  526. assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
  527. // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
  528. assert.equal(el.find('[name="input2"]').val(), 'some used default', 'check input2 value')
  529. assert.equal(el.find('[name="input2"]').prop('required'), false, 'check input2 required')
  530. assert.equal(el.find('[name="input3"]').val(), 'some used default', 'check input3 value')
  531. assert.equal(el.find('[name="input3"]').prop('required'), false, 'check input3 required')
  532. assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
  533. assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
  534. assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
  535. assert.equal(el.find('[name="select2"]').val(), 'false', 'check select2 value')
  536. assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
  537. assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
  538. assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
  539. assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
  540. assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
  541. assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
  542. var params = App.ControllerForm.params(el)
  543. var test_params = {
  544. input1: "",
  545. input2: "some used default",
  546. input3: "some used default",
  547. select1: "false",
  548. select2: "false",
  549. selectmulti2: [ "true", "false" ],
  550. selectmultioption1: [ "false" ],
  551. datetime1: '2015-01-11T12:40:00.000Z',
  552. datetime2: null,
  553. datetime3: '2015-01-11T12:40:00.000Z',
  554. datetime4: null,
  555. date1: '2015-01-11',
  556. date2: null,
  557. date3: '2015-01-11',
  558. date4: null,
  559. }
  560. assert.deepEqual(params, test_params, 'form param check 2')
  561. errors = form.validate(params)
  562. test_errors = {
  563. datetime4: "is required",
  564. date4: "is required",
  565. }
  566. assert.deepEqual(errors, test_errors, 'validation errors check')
  567. App.ControllerForm.validate({ errors: errors, form: el })
  568. el.find('[name="select1"]').val('true')
  569. el.find('[name="select1"]').trigger('change')
  570. params = App.ControllerForm.params(el)
  571. test_params = {
  572. input1: "",
  573. input2: "some used default",
  574. input3: "some used default",
  575. select1: "true",
  576. select2: "false",
  577. selectmulti2: [ "true", "false" ],
  578. selectmultioption1: [ "false" ],
  579. datetime1: '2015-01-11T12:40:00.000Z',
  580. datetime2: null,
  581. datetime3: '2015-01-11T12:40:00.000Z',
  582. datetime4: null,
  583. date1: '2015-01-11',
  584. date2: null,
  585. date3: '2015-01-11',
  586. date4: null,
  587. }
  588. assert.deepEqual(params, test_params, 'form param check 3')
  589. });
  590. QUnit.test("form handler check with and without fieldset", assert => {
  591. // assert.deepEqual(item, test.value, 'group set/get tests' );
  592. // mix default and params -> check it -> add note
  593. // test auto completion
  594. // show/hide fields base on field values -> bind changed event
  595. // form validation
  596. // form params check
  597. // add signature only if form_state is empty
  598. $('#qunit').append('<hr><h1>form handler check with and without fieldset</h1><form id="form5"></form>')
  599. var el = $('#form5')
  600. var defaults = {
  601. select1: 'a',
  602. select2: '',
  603. }
  604. var formChanges = function(params, attribute, attributes, classname, form, ui) {
  605. //console.log('FROM', form)
  606. if (params['select1'] === 'b') {
  607. //console.log('select1 -> b', params)
  608. var item = {
  609. name: 'select2',
  610. display: 'Select2',
  611. tag: 'select',
  612. null: true,
  613. options: { 1:'1', 2:'2', 3:'3' },
  614. default: 3,
  615. };
  616. var newElement = ui.formGenItem(item, classname, form)
  617. form.find('[name="select2"]').closest('.form-group').replaceWith(newElement)
  618. }
  619. if (params['select1'] === 'a') {
  620. //console.log('select1 -> a', params)
  621. var item = {
  622. name: 'select2',
  623. display: 'Select2',
  624. tag: 'select',
  625. null: true,
  626. options: { 1:'1', 2:'2', 3:'3' },
  627. default: 1,
  628. };
  629. var newElement = ui.formGenItem(item, classname, form)
  630. form.find('[name="select2"]').closest('.form-group').replaceWith(newElement)
  631. }
  632. }
  633. new App.ControllerForm({
  634. el: el,
  635. model: {
  636. configure_attributes: [
  637. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { a: 'a', b: 'b' }, default: 'b'},
  638. { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { 1:'1', 2:'2', 3:'3' }, default: 2 },
  639. ],
  640. },
  641. params: defaults,
  642. handlers: [
  643. formChanges,
  644. ],
  645. //noFieldset: true,
  646. });
  647. assert.equal(el.find('[name="select1"]').val(), 'a', 'check select1 value')
  648. assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
  649. assert.equal(el.find('[name="select2"]').val(), '1', 'check select2 value')
  650. assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
  651. var params = App.ControllerForm.params(el)
  652. var test_params = {
  653. select1: 'a',
  654. select2: '1',
  655. }
  656. assert.deepEqual(params, test_params, 'form param check 4')
  657. el.find('[name="select1"]').val('b')
  658. el.find('[name="select1"]').trigger('change')
  659. params = App.ControllerForm.params(el)
  660. test_params = {
  661. select1: 'b',
  662. select2: '3',
  663. }
  664. assert.deepEqual(params, test_params, 'form param check 5')
  665. el.find('[name="select1"]').val('a')
  666. el.find('[name="select1"]').trigger('change')
  667. params = App.ControllerForm.params(el)
  668. test_params = {
  669. select1: 'a',
  670. select2: '1',
  671. }
  672. assert.deepEqual(params, test_params, 'form param check 6')
  673. // test with noFieldset
  674. el.empty()
  675. new App.ControllerForm({
  676. el: el,
  677. model: {
  678. configure_attributes: [
  679. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { a: 'a', b: 'b' }, default: 'b'},
  680. { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { 1:'1', 2:'2', 3:'3' }, default: 2 },
  681. ],
  682. },
  683. params: defaults,
  684. handlers: [
  685. formChanges,
  686. ],
  687. noFieldset: true,
  688. });
  689. assert.equal(el.find('[name="select1"]').val(), 'a', 'check select1 value')
  690. assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
  691. assert.equal(el.find('[name="select2"]').val(), '1', 'check select2 value')
  692. assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
  693. var params = App.ControllerForm.params(el)
  694. var test_params = {
  695. select1: 'a',
  696. select2: '1',
  697. }
  698. assert.deepEqual(params, test_params, 'form param check 7')
  699. el.find('[name="select1"]').val('b')
  700. el.find('[name="select1"]').trigger('change')
  701. params = App.ControllerForm.params(el)
  702. test_params = {
  703. select1: 'b',
  704. select2: '3',
  705. }
  706. assert.deepEqual(params, test_params, 'form param check 8')
  707. el.find('[name="select1"]').val('a')
  708. el.find('[name="select1"]').trigger('change')
  709. params = App.ControllerForm.params(el)
  710. test_params = {
  711. select1: 'a',
  712. select2: '1',
  713. }
  714. assert.deepEqual(params, test_params, 'form param check 9')
  715. });
  716. QUnit.test("form postmaster filter", assert => {
  717. App.TicketPriority.refresh([
  718. {
  719. id: 1,
  720. name: 'prio 1',
  721. },
  722. {
  723. id: 2,
  724. name: 'prio 2',
  725. },
  726. ] )
  727. App.Group.refresh([
  728. {
  729. id: 1,
  730. name: 'group 1',
  731. },
  732. {
  733. id: 2,
  734. name: 'group 2',
  735. },
  736. ] )
  737. $('#qunit').append('<hr><h1>form postmaster filter</h1><form id="form6"></form>')
  738. var el = $('#form6')
  739. var defaults = {
  740. input2: 'some name',
  741. match: {
  742. from: {
  743. operator: 'contains',
  744. value: 'some@address',
  745. },
  746. subject: {
  747. operator: 'contains',
  748. value: 'some subject',
  749. },
  750. cc: {
  751. operator: 'starts with one of',
  752. value: ['a', 'b', 'c'],
  753. },
  754. },
  755. set: {
  756. 'x-zammad-ticket-customer_id': {
  757. value: 'customer',
  758. value_completion: ''
  759. },
  760. 'x-zammad-ticket-group_id': {
  761. value: '1'
  762. },
  763. 'x-zammad-ticket-owner_id': {
  764. value: 'owner',
  765. value_completion: ''
  766. },
  767. 'x-zammad-ticket-priority_id': {
  768. value: '1'
  769. },
  770. 'x-zammad-ticket-tags': {
  771. operator: 'add',
  772. value: 'test, test1'
  773. }
  774. },
  775. }
  776. new App.ControllerForm({
  777. el: el,
  778. model: {
  779. configure_attributes: [
  780. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' },
  781. { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
  782. { name: 'match', display: 'Match', tag: 'postmaster_match', null: false, default: false},
  783. { name: 'set', display: 'Set', tag: 'postmaster_set', null: false, default: false, user_action: false},
  784. ],
  785. },
  786. params: defaults,
  787. });
  788. params = App.ControllerForm.params(el)
  789. test_params = {
  790. input1: 'some not used default',
  791. input2: 'some name',
  792. match: {
  793. from: {
  794. operator: 'contains',
  795. value: 'some@address'
  796. },
  797. subject: {
  798. operator: 'contains',
  799. value: 'some subject'
  800. },
  801. cc: {
  802. operator: 'starts with one of',
  803. value: ['a', 'b', 'c'],
  804. },
  805. },
  806. set: {
  807. 'x-zammad-ticket-customer_id': {
  808. value: 'customer',
  809. value_completion: ''
  810. },
  811. 'x-zammad-ticket-group_id': {
  812. value: '1'
  813. },
  814. 'x-zammad-ticket-owner_id': {
  815. value: 'owner',
  816. value_completion: ''
  817. },
  818. 'x-zammad-ticket-priority_id': {
  819. value: '1'
  820. },
  821. 'x-zammad-ticket-tags': {
  822. operator: 'add',
  823. value: 'test, test1'
  824. }
  825. },
  826. };
  827. assert.deepEqual(params, test_params, 'form param check 10')
  828. el.find('[name="set::x-zammad-ticket-priority_id::value"]').closest('.js-filterElement').find('.js-remove').trigger('click')
  829. el.find('[name="set::x-zammad-ticket-customer_id::value"]').closest('.js-filterElement').find('.js-remove').trigger('click')
  830. params = App.ControllerForm.params(el)
  831. test_params = {
  832. input1: 'some not used default',
  833. input2: 'some name',
  834. match: {
  835. from: {
  836. operator: 'contains',
  837. value: 'some@address'
  838. },
  839. subject: {
  840. operator: 'contains',
  841. value: 'some subject'
  842. },
  843. cc: {
  844. operator: 'starts with one of',
  845. value: ['a', 'b', 'c'],
  846. },
  847. },
  848. set: {
  849. 'x-zammad-ticket-owner_id': {
  850. value: 'owner',
  851. value_completion: ''
  852. },
  853. 'x-zammad-ticket-group_id': {
  854. value: '1'
  855. },
  856. 'x-zammad-ticket-tags': {
  857. operator: 'add',
  858. value: 'test, test1'
  859. },
  860. },
  861. };
  862. assert.deepEqual(params, test_params, 'form param check 11')
  863. el.find('.postmaster_set .js-filterElement').last().find('.filter-controls .js-add').trigger('click')
  864. params = App.ControllerForm.params(el)
  865. test_params = {
  866. input1: 'some not used default',
  867. input2: 'some name',
  868. match: {
  869. from: {
  870. operator: 'contains',
  871. value: 'some@address'
  872. },
  873. subject: {
  874. operator: 'contains',
  875. value: 'some subject'
  876. },
  877. cc: {
  878. operator: 'starts with one of',
  879. value: ['a', 'b', 'c'],
  880. },
  881. },
  882. set: {
  883. 'x-zammad-ticket-owner_id': {
  884. value: 'owner',
  885. value_completion: ''
  886. },
  887. 'x-zammad-ticket-group_id': {
  888. value: '1'
  889. },
  890. 'x-zammad-ticket-tags': {
  891. operator: 'add',
  892. value: 'test, test1'
  893. },
  894. 'x-zammad-ticket-title': {
  895. value: ''
  896. },
  897. },
  898. };
  899. assert.deepEqual(params, test_params, 'form param check 12')
  900. App.Delay.set(function() {
  901. QUnit.test("form postmaster filter - needed to do delayed because of tag ui", assert => {
  902. el.find('[name="set::x-zammad-ticket-tags::value"]').closest('.js-filterElement').find('.token .close').last().trigger('click')
  903. params = App.ControllerForm.params(el)
  904. test_params = {
  905. input1: 'some not used default',
  906. input2: 'some name',
  907. match: {
  908. from: {
  909. operator: 'contains',
  910. value: 'some@address'
  911. },
  912. subject: {
  913. operator: 'contains',
  914. value: 'some subject'
  915. },
  916. cc: {
  917. operator: 'starts with one of',
  918. value: ['a', 'b', 'c'],
  919. },
  920. },
  921. set: {
  922. 'x-zammad-ticket-owner_id': {
  923. value: 'owner',
  924. value_completion: ''
  925. },
  926. 'x-zammad-ticket-group_id': {
  927. value: '1'
  928. },
  929. 'x-zammad-ticket-priority_id': {
  930. value: '1'
  931. },
  932. 'x-zammad-ticket-tags': {
  933. operator: 'add',
  934. value: 'test'
  935. },
  936. },
  937. };
  938. assert.deepEqual(params, test_params, 'form param check 13')
  939. })
  940. }, 500);
  941. });
  942. QUnit.test("form selector", assert => {
  943. $('#qunit').append('<hr><h1>form selector</h1><div><form id="form7"></form></div>')
  944. var el = $('#form7')
  945. var defaults = {
  946. input2: 'some name66',
  947. }
  948. new App.ControllerForm({
  949. el: el,
  950. model: {
  951. configure_attributes: [
  952. { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default33' },
  953. { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
  954. ],
  955. },
  956. params: defaults,
  957. });
  958. test_params = {
  959. input1: 'some not used default33',
  960. input2: 'some name66',
  961. };
  962. params = App.ControllerForm.params(el)
  963. assert.deepEqual(params, test_params, 'form param check 14 via $("#form")')
  964. params = App.ControllerForm.params(el.find('input'))
  965. assert.deepEqual(params, test_params, 'form param check 15 via $("#form").find("input")')
  966. params = App.ControllerForm.params(el.parent())
  967. assert.deepEqual(params, test_params, 'form param check 16 via $("#form").parent()')
  968. });
  969. QUnit.test("form params check 2", assert => {
  970. $('#qunit').append('<hr><h1>form params check</h1><form id="form9"></form>')
  971. var el = $('#form9')
  972. var defaults = {
  973. select1: false,
  974. select2: true,
  975. select3: null,
  976. select4: undefined,
  977. }
  978. new App.ControllerForm({
  979. el: el,
  980. model: {
  981. configure_attributes: [
  982. { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' } },
  983. { name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' } },
  984. { name: 'select3', display: 'Select3', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select3' } },
  985. { name: 'select4', display: 'Select4', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select4' } },
  986. ],
  987. },
  988. params: defaults,
  989. autofocus: true
  990. });
  991. params = App.ControllerForm.params(el)
  992. test_params = {
  993. select1: 'false',
  994. select2: 'true',
  995. select3: '',
  996. select4: '',
  997. }
  998. //console.log('params', params)
  999. //console.log('test_params', test_params)
  1000. assert.deepEqual(params, test_params, 'form param check 17')
  1001. });
  1002. QUnit.test("form params check direct", assert => {
  1003. $('#qunit').append('<hr><h1>form params check direct</h1><form id="form10"><input name="a" value="b"><input name="l::l::l1" value="d"><input name="l::l::" value><input name="f::f::" value><input name="f::f::f1" value="e"></form>')
  1004. var el = $('#form10')
  1005. params = App.ControllerForm.params(el)
  1006. test_params = {
  1007. a: 'b',
  1008. l: {
  1009. l: {
  1010. l1: 'd',
  1011. '': '',
  1012. },
  1013. },
  1014. f: {
  1015. f: {
  1016. f1: 'e',
  1017. '': '',
  1018. },
  1019. },
  1020. }
  1021. //console.log('params', params)
  1022. //console.log('test_params', test_params)
  1023. assert.deepEqual(params, test_params, 'form param check 18')
  1024. });
  1025. QUnit.test("object manager form 1", assert => {
  1026. $('#qunit').append('<hr><h1>object manager 1</h1><form id="form11"></form>')
  1027. var el = $('#form11')
  1028. var defaults = {}
  1029. new App.ControllerForm({
  1030. el: el,
  1031. model: {
  1032. configure_attributes: [
  1033. { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
  1034. ],
  1035. },
  1036. params: $.extend(defaults, { object: 'Ticket' }),
  1037. autofocus: true
  1038. });
  1039. var params = App.ControllerForm.params(el)
  1040. var test_params = {
  1041. data_option: {
  1042. default: "",
  1043. linktemplate: "",
  1044. maxlength: 120,
  1045. type: "text"
  1046. },
  1047. data_type: "input",
  1048. screens: {
  1049. create_middle: {
  1050. "ticket.agent": {
  1051. shown: true,
  1052. required: false,
  1053. },
  1054. "ticket.customer": {
  1055. shown: true,
  1056. required: false,
  1057. }
  1058. },
  1059. edit: {
  1060. "ticket.agent": {
  1061. shown: true,
  1062. required: false,
  1063. },
  1064. "ticket.customer": {
  1065. shown: true,
  1066. required: false,
  1067. }
  1068. }
  1069. }
  1070. }
  1071. assert.deepEqual(params, test_params, 'form param check 19')
  1072. el.find('[name=data_type]').val('datetime').trigger('change')
  1073. params = App.ControllerForm.params(el)
  1074. var test_params = {
  1075. data_option: {
  1076. diff: null,
  1077. future: true,
  1078. past: true
  1079. },
  1080. data_type: "datetime",
  1081. screens: {
  1082. create_middle: {
  1083. "ticket.agent": {
  1084. shown: true,
  1085. required: false,
  1086. },
  1087. "ticket.customer": {
  1088. shown: true,
  1089. required: false,
  1090. }
  1091. },
  1092. edit: {
  1093. "ticket.agent": {
  1094. shown: true,
  1095. required: false,
  1096. },
  1097. "ticket.customer": {
  1098. shown: true,
  1099. required: false,
  1100. }
  1101. }
  1102. }
  1103. }
  1104. assert.deepEqual(params, test_params, 'form param check 20')
  1105. });
  1106. QUnit.test("object manager form 2", assert => {
  1107. $('#qunit').append('<hr><h1>object manager 2</h1><form id="form12"></form>')
  1108. var el = $('#form12')
  1109. var defaults = {
  1110. id: 123,
  1111. data_option: {
  1112. default: "",
  1113. maxlength: 120,
  1114. type: "text"
  1115. },
  1116. data_type: "input",
  1117. screens: {
  1118. create_middle: {
  1119. "ticket.agent": {
  1120. shown: true,
  1121. required: false,
  1122. },
  1123. },
  1124. edit: {
  1125. "ticket.agent": {
  1126. shown: true,
  1127. required: false,
  1128. },
  1129. }
  1130. }
  1131. }
  1132. new App.ControllerForm({
  1133. el: el,
  1134. model: {
  1135. configure_attributes: [
  1136. { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
  1137. ],
  1138. },
  1139. params: $.extend(defaults, { object: 'Ticket' }),
  1140. autofocus: true
  1141. });
  1142. var params = App.ControllerForm.params(el)
  1143. var test_params = {
  1144. data_option: {
  1145. default: "",
  1146. linktemplate: "",
  1147. maxlength: 120,
  1148. type: "text"
  1149. },
  1150. data_type: "input",
  1151. screens: {
  1152. create_middle: {
  1153. "ticket.agent": {
  1154. shown: true,
  1155. required: false,
  1156. },
  1157. "ticket.customer": {
  1158. shown: false,
  1159. required: false,
  1160. }
  1161. },
  1162. edit: {
  1163. "ticket.agent": {
  1164. shown: true,
  1165. required: false,
  1166. },
  1167. "ticket.customer": {
  1168. shown: false,
  1169. required: false,
  1170. }
  1171. }
  1172. }
  1173. }
  1174. assert.deepEqual(params, test_params, 'form param check 21')
  1175. });
  1176. QUnit.test("object manager form 3", assert => {
  1177. $('#qunit').append('<hr><h1>object manager 3</h1><form id="form13"></form>')
  1178. var el = $('#form13')
  1179. var defaults = {}
  1180. new App.ControllerForm({
  1181. el: el,
  1182. model: {
  1183. configure_attributes: [
  1184. { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
  1185. ],
  1186. },
  1187. params: $.extend(defaults, { object: 'Ticket' }),
  1188. autofocus: true
  1189. });
  1190. var params = App.ControllerForm.params(el)
  1191. var test_params = {
  1192. data_option: {
  1193. default: "",
  1194. linktemplate: "",
  1195. maxlength: 120,
  1196. type: "text"
  1197. },
  1198. data_type: "input",
  1199. screens: {
  1200. create_middle: {
  1201. "ticket.agent": {
  1202. shown: true,
  1203. required: false,
  1204. },
  1205. "ticket.customer": {
  1206. shown: true,
  1207. required: false,
  1208. }
  1209. },
  1210. edit: {
  1211. "ticket.agent": {
  1212. shown: true,
  1213. required: false,
  1214. },
  1215. "ticket.customer": {
  1216. shown: true,
  1217. required: false,
  1218. }
  1219. }
  1220. }
  1221. }
  1222. assert.deepEqual(params, test_params, 'form param check 22')
  1223. el.find('[name="screens::create_middle::ticket.customer::shown"]').trigger('click')
  1224. el.find('[name="screens::edit::ticket.customer::shown"]').trigger('click')
  1225. params = App.ControllerForm.params(el)
  1226. test_params = {
  1227. data_option: {
  1228. default: "",
  1229. linktemplate: "",
  1230. maxlength: 120,
  1231. type: "text"
  1232. },
  1233. data_type: "input",
  1234. screens: {
  1235. create_middle: {
  1236. "ticket.agent": {
  1237. shown: true,
  1238. required: false,
  1239. },
  1240. "ticket.customer": {
  1241. shown: false,
  1242. required: false,
  1243. }
  1244. },
  1245. edit: {
  1246. "ticket.agent": {
  1247. shown: true,
  1248. required: false,
  1249. },
  1250. "ticket.customer": {
  1251. shown: false,
  1252. required: false,
  1253. }
  1254. }
  1255. }
  1256. }
  1257. assert.deepEqual(params, test_params, 'form param check 23')
  1258. });
  1259. QUnit.test("check if select value is not existing but is shown", assert => {
  1260. $('#qunit').append('<hr><h1>check if select value is not existing but is shown</h1><form id="form17"></form>')
  1261. var el = $('#form17')
  1262. var defaults = {
  1263. select1: 'NOT EXISTING',
  1264. }
  1265. new App.ControllerForm({
  1266. el: el,
  1267. model: {
  1268. configure_attributes: [
  1269. { name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
  1270. ],
  1271. },
  1272. params: defaults,
  1273. });
  1274. params = App.ControllerForm.params(el)
  1275. test_params = {
  1276. select1: 'NOT EXISTING',
  1277. }
  1278. assert.deepEqual(params, test_params)
  1279. assert.equal('AA', el.find('[name=select1] option')[0].text)
  1280. assert.equal('äöü', el.find('[name=select1] option')[1].text)
  1281. assert.equal('b', el.find('[name=select1] option')[2].text)
  1282. assert.equal('B', el.find('[name=select1] option')[3].text)
  1283. assert.equal('NOT EXISTING', el.find('[name=select1] option')[4].text)
  1284. assert.equal('XX', el.find('[name=select1] option')[5].text)
  1285. });
  1286. QUnit.test("check if select value is not existing and is not shown", assert => {
  1287. $('#qunit').append('<hr><h1>check if select value is not existing and is not shown</h1><form id="form18"></form>')
  1288. var el = $('#form18')
  1289. var defaults = {
  1290. select1: 'NOT EXISTING',
  1291. }
  1292. new App.ControllerForm({
  1293. el: el,
  1294. model: {
  1295. configure_attributes: [
  1296. { name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
  1297. ],
  1298. },
  1299. params: defaults,
  1300. rejectNonExistentValues: true,
  1301. });
  1302. params = App.ControllerForm.params(el)
  1303. test_params = {
  1304. select1: 'XY',
  1305. }
  1306. assert.deepEqual(params, test_params)
  1307. assert.equal('AA', el.find('[name=select1] option')[0].text)
  1308. assert.equal('äöü', el.find('[name=select1] option')[1].text)
  1309. assert.equal('b', el.find('[name=select1] option')[2].text)
  1310. assert.equal('B', el.find('[name=select1] option')[3].text)
  1311. assert.equal('XX', el.find('[name=select1] option')[4].text)
  1312. });
  1313. QUnit.test("time range form 1", assert => {
  1314. $('#qunit').append('<hr><h1>time range form 1</h1><form id="form14"></form>')
  1315. var el = $('#form14')
  1316. var defaults = {}
  1317. new App.ControllerForm({
  1318. el: el,
  1319. model: {
  1320. configure_attributes: [
  1321. { name: 'time_range', display: 'Format', tag: 'time_range', null: false },
  1322. ],
  1323. },
  1324. params: $.extend(defaults, { object: 'Ticket' }),
  1325. autofocus: true
  1326. });
  1327. var params = App.ControllerForm.params(el)
  1328. var test_params = {
  1329. "time_range": {
  1330. "range": "minute",
  1331. "value": "1"
  1332. }
  1333. }
  1334. assert.deepEqual(params, test_params, 'base form param range check')
  1335. el.find('.js-range').val('minute').trigger('change')
  1336. el.find('.js-valueRangeSelector .js-value').val('120').trigger('change')
  1337. params = App.ControllerForm.params(el)
  1338. test_params = {
  1339. "time_range": {
  1340. "range": "minute",
  1341. "value": "120"
  1342. }
  1343. }
  1344. assert.deepEqual(params, test_params, 'form param minute range check')
  1345. el.find('.js-range').val('hour').trigger('change')
  1346. el.find('.js-valueRangeSelector .js-value').val('48').trigger('change')
  1347. params = App.ControllerForm.params(el)
  1348. test_params = {
  1349. "time_range": {
  1350. "range": "hour",
  1351. "value": "48"
  1352. }
  1353. }
  1354. assert.deepEqual(params, test_params, 'form param hour range check')
  1355. el.find('.js-range').val('day').trigger('change')
  1356. el.find('.js-valueRangeSelector .js-value').val('31').trigger('change')
  1357. params = App.ControllerForm.params(el)
  1358. test_params = {
  1359. "time_range": {
  1360. "range": "day",
  1361. "value": "31"
  1362. }
  1363. }
  1364. assert.deepEqual(params, test_params, 'form param day range check')
  1365. el.find('.js-range').val('month').trigger('change')
  1366. el.find('.js-valueRangeSelector .js-value').val('12').trigger('change')
  1367. params = App.ControllerForm.params(el)
  1368. test_params = {
  1369. "time_range": {
  1370. "range": "month",
  1371. "value": "12"
  1372. }
  1373. }
  1374. assert.deepEqual(params, test_params, 'form param month range check')
  1375. el.find('.js-range').val('year').trigger('change')
  1376. el.find('.js-valueRangeSelector .js-value').val('20').trigger('change')
  1377. params = App.ControllerForm.params(el)
  1378. test_params = {
  1379. "time_range": {
  1380. "range": "year",
  1381. "value": "20"
  1382. }
  1383. }
  1384. assert.deepEqual(params, test_params, 'form param year range check')
  1385. el.find('.js-range').val('minute').trigger('change')
  1386. el.find('.js-valueRangeSelector .js-value').val('11').trigger('change')
  1387. el.find('.js-range').val('hour').trigger('change')
  1388. params = App.ControllerForm.params(el)
  1389. test_params = {
  1390. "time_range": {
  1391. "range": "hour",
  1392. "value": "11"
  1393. }
  1394. }
  1395. assert.deepEqual(params, test_params, 'form param selected value hour check')
  1396. el.find('.js-range').val('day').trigger('change')
  1397. params = App.ControllerForm.params(el)
  1398. test_params = {
  1399. "time_range": {
  1400. "range": "day",
  1401. "value": "11"
  1402. }
  1403. }
  1404. assert.deepEqual(params, test_params, 'form param selected value day check')
  1405. el.find('.js-range').val('month').trigger('change')
  1406. params = App.ControllerForm.params(el)
  1407. test_params = {
  1408. "time_range": {
  1409. "range": "month",
  1410. "value": "11"
  1411. }
  1412. }
  1413. assert.deepEqual(params, test_params, 'form param selected value month check')
  1414. el.find('.js-range').val('year').trigger('change')
  1415. params = App.ControllerForm.params(el)
  1416. test_params = {
  1417. "time_range": {
  1418. "range": "year",
  1419. "value": "11"
  1420. }
  1421. }
  1422. assert.deepEqual(params, test_params, 'form param selected value year check')
  1423. });
  1424. QUnit.test("form select with empty option list", assert => {
  1425. $('#qunit').append('<hr><h1>form select with empty option list</h1><form id="form15"></form>')
  1426. var el = $('#form15')
  1427. var defaults = {}
  1428. new App.ControllerForm({
  1429. el: el,
  1430. model: {
  1431. configure_attributes: [
  1432. { name: 'select1', display: 'Select1', tag: 'select', null: true, default: '', options: {}, relation: '', maxlength: 255 },
  1433. { name: 'select2', display: 'Select2', tag: 'select', null: true, default: '', options: {}, relation: '', maxlength: 255, nulloption: true },
  1434. { name: 'select3', display: 'Select3', tag: 'select', null: true, default: '', options: { undefined: 'A', null: 'B'} },
  1435. { name: 'select4', display: 'Select4', tag: 'select', null: true, default: '', options: { 'A': undefined, 'B': null} },
  1436. { name: 'select5', display: 'Select5', tag: 'select', null: true, default: 'A', options: { 'A': undefined, 'B': null} },
  1437. { name: 'select6', display: 'Select6', tag: 'select', null: true, default: undefined, options: { 'A': undefined, 'B': null} },
  1438. ],
  1439. },
  1440. params: defaults,
  1441. autofocus: true
  1442. });
  1443. params = App.ControllerForm.params(el)
  1444. test_params = {
  1445. select2: '',
  1446. select3: 'undefined',
  1447. select4: 'B',
  1448. select5: 'A',
  1449. select6: 'B',
  1450. }
  1451. assert.deepEqual(params, test_params)
  1452. });
  1453. QUnit.test("form elements with sort check", assert => {
  1454. $('#qunit').append('<hr><h1>form elements with sort check</h1><form id="form16"></form>')
  1455. var el = $('#form16')
  1456. var defaults = {}
  1457. new App.ControllerForm({
  1458. el: el,
  1459. model: {
  1460. configure_attributes: [
  1461. { name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
  1462. { name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: 'A', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
  1463. { name: 'radio1', display: 'Radio1', tag: 'radio', null: false, default: 'A', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
  1464. ],
  1465. },
  1466. params: defaults,
  1467. autofocus: true
  1468. });
  1469. params = App.ControllerForm.params(el)
  1470. test_params = {
  1471. select1: 'XY',
  1472. checkbox1: 'A',
  1473. radio1: 'A',
  1474. }
  1475. assert.deepEqual(params, test_params)
  1476. assert.equal('AA', el.find('[name=select1] option')[0].text)
  1477. assert.equal('äöü', el.find('[name=select1] option')[1].text)
  1478. assert.equal('b', el.find('[name=select1] option')[2].text)
  1479. assert.equal('B', el.find('[name=select1] option')[3].text)
  1480. assert.equal('XX', el.find('[name=select1] option')[4].text)
  1481. assert.equal('XX', el.find('[name=checkbox1]')[0].value)
  1482. assert.equal('', el.find('[name=checkbox1]')[1].value)
  1483. assert.equal('XY', el.find('[name=checkbox1]')[2].value)
  1484. assert.equal('B', el.find('[name=checkbox1]')[3].value)
  1485. assert.equal('A', el.find('[name=checkbox1]')[4].value)
  1486. assert.equal('XX', el.find('[name=radio1]')[0].value)
  1487. assert.equal('', el.find('[name=radio1]')[1].value)
  1488. assert.equal('XY', el.find('[name=radio1]')[2].value)
  1489. assert.equal('B', el.find('[name=radio1]')[3].value)
  1490. assert.equal('A', el.find('[name=radio1]')[4].value)
  1491. });
  1492. QUnit.test("form deep nesting", assert => {
  1493. $('#qunit').append('<hr><h1>form selector</h1><div><form id="form19"></form></div>')
  1494. var el = $('#form19')
  1495. var defaults = {
  1496. a: {
  1497. input1: 'a'
  1498. },
  1499. b: {
  1500. c: {
  1501. input2: 'b'
  1502. }
  1503. }
  1504. }
  1505. new App.ControllerForm({
  1506. el: el,
  1507. model: {
  1508. configure_attributes: [
  1509. { name: 'a::input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default33' },
  1510. { name: 'b::c::input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
  1511. ],
  1512. },
  1513. params: defaults,
  1514. });
  1515. params = App.ControllerForm.params(el)
  1516. assert.deepEqual(params, defaults, 'nested params')
  1517. });
  1518. QUnit.test("form with external links", assert => {
  1519. $('#qunit').append('<hr><h1>form with external links</h1><div><form id="form20"></form></div>')
  1520. var el = $('#form20')
  1521. var defaults = {
  1522. a: '133',
  1523. b: 'abc d',
  1524. }
  1525. new App.ControllerForm({
  1526. el: el,
  1527. model: {
  1528. configure_attributes: [
  1529. { name: 'a', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, linktemplate: "https://example.com/?q=#{ticket.a}" },
  1530. { name: 'b', display: 'Select1', tag: 'select', type: 'text', options: { a: 1, b: 2 }, limit: 100, null: true, linktemplate: "https://example.com/?q=#{ticket.b}" },
  1531. ],
  1532. className: 'Ticket',
  1533. },
  1534. params: defaults,
  1535. });
  1536. params = App.ControllerForm.params(el)
  1537. assert.deepEqual(params, defaults)
  1538. assert.equal('https://example.com/?q=133', el.find('input[name="a"]').parents('.controls').find('a[href]').attr('href'))
  1539. assert.equal('https://example.com/?q=abc%20d', el.find('select[name="b"]').parents('.controls').find('a[href]').attr('href'))
  1540. });
  1541. QUnit.test("Fixes #4024 - Tree select value cannot be set to \"-\" (empty) with Trigger/Scheduler/Core workflow.", assert => {
  1542. $('#qunit').append('<hr><h1>Fixes #4024 - Tree select value cannot be set to "-" (empty) with Trigger/Scheduler/Core workflow.</h1><form id="form22"></form>')
  1543. var el = $('#form22')
  1544. new App.ControllerForm({
  1545. el: el,
  1546. model: {
  1547. configure_attributes: [
  1548. { name: '4024_select', display: '4024_select', tag: 'select_search', null: true, nulloption: true, multiple: true, options: { 'a': 'a', 'b': 'b' } },
  1549. { name: '4024_multiselect', display: '4024_multiselect', tag: 'multiselect_search', null: true, nulloption: true, multiple: true, options: { 'a': 'a', 'b': 'b' } },
  1550. { name: '4024_tree_select', display: '4024_tree_select', tag: 'tree_select_search', null: true, nulloption: true, multiple: true, options: [{ 'value': 'a', 'name': 'a'}, { 'value': 'b', 'name': 'b'}] },
  1551. { name: '4024_multi_tree_select', display: '4024_multi_tree_select', tag: 'multi_tree_select', null: true, nulloption: true, multiple: true, options: [{ 'value': 'a', 'name': 'a'}, { 'value': 'b', 'name': 'b'}] },
  1552. ],
  1553. },
  1554. autofocus: true
  1555. });
  1556. assert.equal(el.find('select[name="4024_select"] option[value=""]').text(), '-', '4024_select has nulloption')
  1557. assert.equal(el.find('select[name="4024_multiselect"] option[value=""]').text(), '-', '4024_multiselect has nulloption')
  1558. assert.equal(el.find("div[data-attribute-name=4024_tree_select] .js-option[data-display-name='-'] .searchableSelect-option-text").text().trim(), '-', '4024_tree_select has nulloption')
  1559. assert.equal(el.find("div[data-attribute-name=4024_multi_tree_select] .js-option[data-display-name='-'] .searchableSelect-option-text").text().trim(), '-', '4024_multi_tree_select has nulloption')
  1560. });
  1561. QUnit.test("Fixes #4027 - undefined method `to_hash` on editing select fields in the admin interface after migration to 5.1.", assert => {
  1562. $('#qunit').append('<hr><h1>Fixes #4027 - undefined method `to_hash` on editing select fields in the admin interface after migration to 5.1.</h1><form id="form23"></form>')
  1563. var el = $('#form23')
  1564. new App.ControllerForm({
  1565. el: el,
  1566. model: {
  1567. configure_attributes: [
  1568. { name: '4027_selcet_hash', display: '4027_selcet_hash', tag: 'select', null: true, nulloption: true, options: { 'a': 'a', 'b': 'b' }, value: 'c', historical_options: { c: 'C' } },
  1569. { name: '4027_selcet_array', display: '4027_selcet_array', tag: 'select', null: true, nulloption: true, options: [{ value: 'a', name: 'a' }, { value: 'b', name: 'b' } ], value: 'c', historical_options: { c: 'C' } },
  1570. { name: '4027_multiselect_hash', display: '4027_multiselect_hash', tag: 'multiselect', null: true, nulloption: true, options: { 'a': 'a', 'b': 'b' }, value: ['c'], historical_options: { c: 'C' } },
  1571. { name: '4027_multiselect_array', display: '4027_multiselect_array', tag: 'multiselect', null: true, nulloption: true, options: [{ value: 'a', name: 'a' }, { value: 'b', name: 'b' } ], value: ['c', 'd'], historical_options: { c: 'C', d: 'D' } },
  1572. { name: '4027_tree_select_array', display: '4027_tree_select_array', tag: 'tree_select', null: true, nulloption: true, options: [{ value: 'a', name: 'a' }, { value: 'b', name: 'b' } ], value: 'b::c', historical_options: { 'b::c': 'C' } },
  1573. ],
  1574. },
  1575. autofocus: true
  1576. });
  1577. assert.equal(el.find('select[name="4027_selcet_hash"] option[selected]').text(), 'C', '4027_select has historic text')
  1578. assert.equal(el.find('select[name="4027_selcet_array"] option[selected]').text(), 'C', '4027_selcet_array has historic text')
  1579. assert.equal(el.find('select[name="4027_multiselect_hash"] option[selected]').text(), 'C', '4027_multiselect_hash has historic text')
  1580. assert.equal(el.find('select[name="4027_multiselect_array"] option[selected]').text(), 'CD', '4027_multiselect_array has historic text')
  1581. assert.equal(el.find('div[data-attribute-name="4027_tree_select_array"] .js-input').val(), 'C', '4027_tree_select_array has historic text')
  1582. });
  1583. QUnit.test("object manager form 4", assert => {
  1584. $('#qunit').append('<hr><h1>object manager 1</h1><form id="form21"></form>')
  1585. var el = $('#form21')
  1586. var defaults = {
  1587. data_type: 'select'
  1588. }
  1589. new App.ControllerForm({
  1590. el: el,
  1591. model: {
  1592. configure_attributes: [
  1593. { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
  1594. ],
  1595. },
  1596. params: $.extend(defaults, { object: 'Ticket' }),
  1597. autofocus: true
  1598. });
  1599. var params = App.ControllerForm.params(el)
  1600. var test_params = {
  1601. "data_option": {
  1602. "customsort": undefined,
  1603. "default": undefined,
  1604. "linktemplate": "",
  1605. "translate": false
  1606. },
  1607. "data_type": "select",
  1608. "screens": {
  1609. "create_middle": {
  1610. "ticket.agent": {
  1611. "required": false,
  1612. "shown": true
  1613. },
  1614. "ticket.customer": {
  1615. "required": false,
  1616. "shown": true
  1617. }
  1618. },
  1619. "edit": {
  1620. "ticket.agent": {
  1621. "required": false,
  1622. "shown": true
  1623. },
  1624. "ticket.customer": {
  1625. "required": false,
  1626. "shown": true
  1627. }
  1628. }
  1629. }
  1630. }
  1631. assert.deepEqual(params, test_params, 'form param check 21')
  1632. $("#form21 select[name='data_option::translate']").val('true')
  1633. var params = App.ControllerForm.params(el)
  1634. var test_params = {
  1635. "data_option": {
  1636. "customsort": undefined,
  1637. "default": undefined,
  1638. "linktemplate": "",
  1639. "translate": true
  1640. },
  1641. "data_type": "select",
  1642. "screens": {
  1643. "create_middle": {
  1644. "ticket.agent": {
  1645. "required": false,
  1646. "shown": true
  1647. },
  1648. "ticket.customer": {
  1649. "required": false,
  1650. "shown": true
  1651. }
  1652. },
  1653. "edit": {
  1654. "ticket.agent": {
  1655. "required": false,
  1656. "shown": true
  1657. },
  1658. "ticket.customer": {
  1659. "required": false,
  1660. "shown": true
  1661. }
  1662. }
  1663. }
  1664. }
  1665. assert.deepEqual(params, test_params, 'form param check 21')
  1666. })