123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839 |
- // form
- QUnit.test("form without @el", assert => {
- var form = new App.ControllerForm()
- assert.equal($(form.html()).is('div'), true)
- assert.equal($(form.html()).hasClass('alert'), true)
- assert.equal($(form.html()).hasClass('hide'), true)
- })
- QUnit.test("form elements check", assert => {
- // assert.deepEqual(item, test.value, 'group set/get tests' );
- $('#qunit').append('<hr><h1>form elements check</h1><form id="form1"></form>')
- var el = $('#form1')
- var defaults = {
- input2: '123abc',
- password2: 'pw1234<l>',
- textarea2: 'lalu <l> lalu',
- select1: false,
- select2: true,
- selectmulti1: [ false ],
- selectmulti2: [ false, true ],
- selectmultioption1: [ false ],
- selectmultioption2: [ false, true ],
- richtext2: 'lalu <l> lalu',
- datetime1: Date.parse('2015-01-11T12:40:00Z'),
- checkbox1: [],
- checkbox2: '1',
- boolean1: true,
- boolean2: false,
- switch1: true,
- switch2: false,
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: defaults['input1'] },
- { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: false, default: defaults['input2'] },
- { name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: true, default: defaults['password1'] },
- { name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false, default: defaults['password2'] },
- { name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: true, upload: true, default: defaults['textarea1'] },
- { name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: defaults['textarea2'] },
- { name: 'textarea3', display: 'Textarea3', tag: 'textarea', limit: 100, null: false, upload: true, default: defaults['textarea3'] },
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: defaults['select1'] },
- { name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' }, default: defaults['select2'] },
- { name: 'selectmulti1', display: 'SelectMulti1', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti1'] },
- { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: defaults['selectmulti2'] },
- { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: defaults['selectmultioption1'] },
- { 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'] },
- { name: 'richtext1', display: 'Richtext1', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext1'] },
- { name: 'richtext2', display: 'Richtext2', tag: 'richtext', limit: 100, null: true, upload: true, default: defaults['richtext2'] },
- { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
- { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: false, default: defaults['datetime2'] },
- { name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
- { name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
- { name: 'boolean1', display: 'Boolean1', tag: 'boolean', null: false, default: defaults['boolean1'] },
- { name: 'boolean2', display: 'Boolean2', tag: 'boolean', null: false, default: defaults['boolean2'] },
- { name: 'boolean3', display: 'Boolean3', tag: 'boolean', null: false, default: defaults['boolean3'] },
- { name: 'switch1', display: 'Switch1', tag: 'switch', null: false, default: defaults['switch1'] },
- { name: 'switch2', display: 'Switch2', tag: 'switch', null: false, default: defaults['switch2'] },
- { name: 'switch3', display: 'Switch3', tag: 'switch', null: false, default: defaults['switch3'] },
- ]
- },
- autofocus: true
- });
- assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
- assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
- // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
- assert.equal(el.find('[name="input2"]').val(), '123abc', 'check input2 value')
- assert.equal(el.find('[name="input2"]').prop('required'), true, 'check input2 required')
- assert.equal(el.find('[name="input2"]').is(":focus"), false, 'check input2 focus')
- assert.equal(el.find('[name="password1"]').val(), '', 'check password1 value')
- assert.equal(el.find('[name="password1_confirm"]').val(), '', 'check password1 value')
- assert.equal(el.find('[name="password1"]').prop('required'), false, 'check password1 required')
- assert.equal(el.find('[name="password1"]').is(":focus"), false, 'check password1 focus')
- assert.equal(el.find('[name="password2"]').val(), 'pw1234<l>', 'check password2 value')
- assert.equal(el.find('[name="password2_confirm"]').val(), 'pw1234<l>', 'check password2 value')
- assert.equal(el.find('[name="password2"]').prop('required'), true, 'check password2 required')
- assert.equal(el.find('[name="password2"]').is(":focus"), false, 'check password2 focus')
- assert.equal(el.find('[name="textarea1"]').val(), '', 'check textarea1 value')
- assert.equal(el.find('[name="textarea1"]').prop('required'), false, 'check textarea1 required')
- assert.equal(el.find('[name="textarea1"]').is(":focus"), false, 'check textarea1 focus')
- assert.equal(el.find('[name="textarea2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
- assert.equal(el.find('[name="textarea2"]').prop('required'), true, 'check textarea2 required')
- assert.equal(el.find('[name="textarea2"]').is(":focus"), false, 'check textarea2 focus')
- assert.equal(el.find('[name="textarea2"]').prop("rows"), 6, 'check textarea2 rows')
- assert.equal(el.find('[name="textarea3"]').prop("rows"), 4, 'check textarea3 rows (default value)')
- assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
- assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
- assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
- assert.equal(el.find('[name="select2"]').val(), 'true', 'check select2 value')
- assert.equal(el.find('[name="select2"]').prop('required'), true, 'check select2 required')
- assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
- assert.equal(el.find('[name="selectmulti1"]').val(), 'false', 'check selectmulti1 value')
- assert.equal(el.find('[name="selectmulti1"]').prop('required'), false, 'check selectmulti1 required')
- assert.equal(el.find('[name="selectmulti1"]').is(":focus"), false, 'check selectmulti1 focus')
- assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
- assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
- //equal(el.find('[name="richtext1"]').val(), '', 'check textarea1 value')
- //equal(el.find('[name="richtext1"]').prop('required'), false, 'check textarea1 required')
- assert.equal(el.find('[name="richtext1"]').is(":focus"), false, 'check textarea1 focus')
- //equal(el.find('[name="richtext2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
- //equal(el.find('[name="richtext2"]').prop('required'), true, 'check textarea2 required')
- assert.equal(el.find('[name="richtext2"]').is(":focus"), false, 'check textarea2 focus')
- assert.equal(el.find('[name="checkbox1"]').first().is(":checked"), false)
- assert.equal(el.find('[name="checkbox1"]').last().is(":checked"), false)
- assert.equal(el.find('[name="checkbox2"]').is(":checked"), true)
- assert.equal(el.find('[name="boolean1"]').val(), 'true')
- assert.equal(el.find('[name="boolean1"]').val(), 'true')
- assert.equal(el.find('[name="boolean2"]').val(), 'false')
- assert.equal(el.find('[name="switch1"]').is(':checked'), true)
- assert.equal(el.find('[name="switch2"]').is(':checked'), false)
- assert.equal(el.find('[name="switch3"]').is(':checked'), false)
- });
- QUnit.test("form params check 1", assert => {
- // assert.deepEqual(item, test.value, 'group set/get tests' );
- $('#qunit').append('<hr><h1>form params check</h1><form id="form2"></form>')
- var el = $('#form2')
- var defaults = {
- input2: '123abc',
- password2: 'pw1234<l>',
- textarea2: 'lalu <l> lalu',
- select1: false,
- select2: true,
- select3: null,
- select4: undefined,
- select5: false,
- selectmulti1: [ false ],
- selectmulti2: [ false, true ],
- selectmulti3: [ false ],
- selectmultioption1: [ false ],
- selectmultioption2: [ false, true ],
- selectmultioption2: [ false, true ],
- selectmultioption3: [ false ],
- autocompletion2: 'id2',
- autocompletion2_autocompletion_value_shown: 'value2',
- richtext2: '<div>lalu <b>b</b> lalu</div>',
- richtext3: '<div></div>',
- richtext4: '<div>lalu <i>b</i> lalu</div>',
- richtext5: '<div></div>',
- richtext6: '<div>lalu <b>b</b> lalu</div>',
- richtext7: "<div> <div> \n</div> \n</div>",
- richtext8: '<div>lalu <i>b</i> lalu</div>',
- richtext9: '<div>lalu <b>b</b> lalu</div>',
- datetime1: new Date(Date.parse('2015-01-11T12:40:00Z') ),
- datetime3: new Date(Date.parse('2015-01-11T12:40:00Z') ),
- datetime5: new Date(Date.parse('2015-01-11T12:40:00Z') ),
- date1: '2015-01-11',
- date3: '2015-01-11',
- date5: '2015-01-11',
- active1: true,
- active2: false,
- checkbox1: [],
- checkbox2: undefined,
- checkbox3: 'd',
- checkbox5: 'd',
- radiobox1: undefined,
- radiobox2: 'a',
- radiobox3: 'a',
- boolean1: true,
- boolean2: false,
- boolean4: false,
- switch1: true,
- switch2: false,
- switch4: true,
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true },
- { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: false },
- { name: 'input3', display: 'Input3', tag: 'input', type: 'text', limit: 100, null: true, disabled: true },
- { name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: true },
- { name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false },
- { name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: true, upload: true },
- { name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true },
- { name: 'textarea3', display: 'Textarea3', tag: 'textarea', rows: 6, limit: 100, null: true, upload: false, disabled: true },
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' } },
- { name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' } },
- { name: 'select3', display: 'Select3', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select3' } },
- { name: 'select4', display: 'Select4', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select4' } },
- { name: 'select5', display: 'Select5', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, disabled: true },
- { name: 'selectmulti1', display: 'SelectMulti1', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' } },
- { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' } },
- { name: 'selectmulti3', display: 'SelectMulti3', tag: 'select', null: true, multiple: true, options: { true: 'internal', false: 'public' }, disabled: true },
- { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }] },
- { name: 'selectmultioption2', display: 'SelectMultiOption2', tag: 'select', null: false, multiple: true, options: [{ value: true, name: 'A' }, { value: 1, name: 'B'}, { value: false, name: 'C' }] },
- { name: 'selectmultioption3', display: 'SelectMultiOption3', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], disabled: true },
- { 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 },
- { 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 },
- { name: 'richtext1', display: 'Richtext1', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext1'] },
- { name: 'richtext2', display: 'Richtext2', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext2'] },
- { name: 'richtext3', display: 'Richtext3', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext3'] },
- { name: 'richtext4', display: 'Richtext4', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: false, default: defaults['richtext4'] },
- { name: 'richtext5', display: 'Richtext5', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext5'] },
- { name: 'richtext6', display: 'Richtext6', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: true, upload: true, default: defaults['richtext6'] },
- { name: 'richtext7', display: 'Richtext7', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext7'] },
- { name: 'richtext8', display: 'Richtext8', tag: 'richtext', maxlength: 100, null: true, type: 'textonly', multiline: false, default: defaults['richtext8'] },
- { name: 'richtext9', display: 'Richtext9', tag: 'richtext', maxlength: 100, null: true, type: 'richtext', multiline: true, upload: true, default: defaults['richtext9'], disabled: true},
- { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
- { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, default: defaults['datetime2'] },
- { name: 'datetime3', display: 'Datetime3', tag: 'datetime', null: false, default: defaults['datetime3'] },
- { name: 'datetime4', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime4'] },
- { name: 'datetime5', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime5'], disabled: true },
- { name: 'date1', display: 'Date1', tag: 'date', null: true, default: defaults['date1'] },
- { name: 'date2', display: 'Date2', tag: 'date', null: true, default: defaults['date2'] },
- { name: 'date3', display: 'Date3', tag: 'date', null: false, default: defaults['date3'] },
- { name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
- { name: 'date5', display: 'Date4', tag: 'date', null: false, default: defaults['date5'], disabled: true },
- { name: 'active1', display: 'Active1', tag: 'active', default: defaults['active1'] },
- { name: 'active2', display: 'Active2', tag: 'active', default: defaults['active2'] },
- { name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: defaults['checkbox1'], options: { a: 'AA', b: 'BB' } },
- { name: 'checkbox2', display: 'Checkbox2', tag: 'checkbox', null: false, default: defaults['checkbox2'], options: { 1: '11' } },
- { name: 'checkbox3', display: 'Checkbox3', tag: 'checkbox', null: false, default: defaults['checkbox3'], options: { c: 'CC', d: 'DD' } },
- { name: 'checkbox4', display: 'Checkbox4', tag: 'checkbox', null: false, default: defaults['checkbox4'], options: { aa: 'AA', bb: 'BB' } },
- { name: 'checkbox5', display: 'Checkbox5', tag: 'checkbox', null: false, default: defaults['checkbox5'], options: { c: 'CC', d: 'DD' }, disabled: true },
- { name: 'radiobox1', display: 'Radiobox1', tag: 'radio', null: false, default: defaults['radiobox1'], options: { a: 'AA', b: 'BB' } },
- { name: 'radiobox2', display: 'Radiobox2', tag: 'radio', null: false, default: defaults['radiobox2'], options: { a: '11' } },
- { name: 'radiobox3', display: 'Radiobox3', tag: 'radio', null: false, default: defaults['radiobox3'], options: { a: 'AA', b: 'BB' }, disabled: true },
- { name: 'boolean1', display: 'Boolean1', tag: 'boolean', null: false, default: defaults['boolean1'] },
- { name: 'boolean2', display: 'Boolean2', tag: 'boolean', null: false, default: defaults['boolean2'] },
- { name: 'boolean3', display: 'Boolean3', tag: 'boolean', null: false, default: defaults['boolean3'] },
- { name: 'boolean4', display: 'Boolean4', tag: 'boolean', null: false, default: defaults['boolean4'], disabled: true },
- { name: 'switch1', display: 'Switch1', tag: 'switch', null: false, default: defaults['switch1'] },
- { name: 'switch2', display: 'Switch2', tag: 'switch', null: false, default: defaults['switch2'] },
- { name: 'switch3', display: 'Switch3', tag: 'switch', null: false, default: defaults['switch3'] },
- { name: 'switch4', display: 'Switch4', tag: 'switch', null: false, default: defaults['switch4'], disabled: true },
- ],
- },
- params: defaults,
- autofocus: true
- });
- assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
- assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
- // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
- assert.equal(el.find('[name="input2"]').val(), '123abc', 'check input2 value')
- assert.equal(el.find('[name="input2"]').prop('required'), true, 'check input2 required')
- assert.equal(el.find('[name="input2"]').is(":focus"), false, 'check input2 focus')
- assert.equal(el.find('[name="input3"]').prop("disabled"), true, 'check input3 disabled')
- assert.equal(el.find('[name="password1"]').val(), '', 'check password1 value')
- assert.equal(el.find('[name="password1_confirm"]').val(), '', 'check password1 value')
- assert.equal(el.find('[name="password1"]').prop('required'), false, 'check password1 required')
- assert.equal(el.find('[name="password1"]').is(":focus"), false, 'check password1 focus')
- assert.equal(el.find('[name="password2"]').val(), 'pw1234<l>', 'check password2 value')
- assert.equal(el.find('[name="password2_confirm"]').val(), 'pw1234<l>', 'check password2 value')
- assert.equal(el.find('[name="password2"]').prop('required'), true, 'check password2 required')
- assert.equal(el.find('[name="password2"]').is(":focus"), false, 'check password2 focus')
- assert.equal(el.find('[name="textarea1"]').val(), '', 'check textarea1 value')
- assert.equal(el.find('[name="textarea1"]').prop('required'), false, 'check textarea1 required')
- assert.equal(el.find('[name="textarea1"]').is(":focus"), false, 'check textarea1 focus')
- assert.equal(el.find('[name="textarea2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
- assert.equal(el.find('[name="textarea2"]').prop('required'), true, 'check textarea2 required')
- assert.equal(el.find('[name="textarea2"]').is(":focus"), false, 'check textarea2 focus')
- assert.equal(el.find('[name="textarea3"]').prop("disabled"), true, 'check textarea3 disabled')
- assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
- assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
- assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
- assert.equal(el.find('[name="select2"]').val(), 'true', 'check select2 value')
- assert.equal(el.find('[name="select2"]').prop('required'), true, 'check select2 required')
- assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
- assert.equal(el.find('[name="select3"]').val(), '', 'check select3 value')
- assert.equal(el.find('[name="select3"]').prop('required'), true, 'check select3 required')
- assert.equal(el.find('[name="select3"]').is(":focus"), false, 'check select3 focus')
- assert.equal(el.find('[name="select4"]').val(), '', 'check select4 value')
- assert.equal(el.find('[name="select4"]').prop('required'), true, 'check select4 required')
- assert.equal(el.find('[name="select4"]').is(":focus"), false, 'check select4 focus')
- assert.equal(el.find('[name="select5"]').prop("disabled"), true, 'check select5 disabled')
- assert.equal(el.find('[name="selectmulti1"]').val(), 'false', 'check selectmulti1 value')
- assert.equal(el.find('[name="selectmulti1"]').prop('required'), false, 'check selectmulti1 required')
- assert.equal(el.find('[name="selectmulti1"]').is(":focus"), false, 'check selectmulti1 focus')
- assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
- assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
- assert.equal(el.find('[name="selectmulti3"]').prop("disabled"), true, 'check selectmulti3 disabled')
- assert.equal(el.find('[name="selectmultioption3"]').prop("disabled"), true, 'check selectmultioption3 disabled')
- assert.equal(el.find('[name="boolean4"]').prop("disabled"), true, 'check boolean4 disabled')
- assert.equal(el.find('[data-name="richtext9"]').prop("contenteditable"), "false", 'check richtext9 disabled')
- assert.equal(el.find('[name="checkbox5"]').prop("disabled"), true, 'check checkbox5 disabled')
- assert.equal(el.find('[name="radiobox3"]').prop("disabled"), true, 'check radiobox3 disabled')
- assert.equal(el.find('[name="switch4"]').prop("disabled"), true, 'check switch4 disabled')
- params = App.ControllerForm.params(el)
- test_params = {
- input1: '',
- input2: '123abc',
- input3: '',
- password1: '',
- password1_confirm: '',
- password2: 'pw1234<l>',
- password2_confirm: 'pw1234<l>',
- textarea1: '',
- textarea2: 'lalu <l> lalu',
- textarea3: '',
- select1: 'false',
- select2: 'true',
- select3: '',
- select4: '',
- select5: 'false',
- selectmulti1: [ 'false' ],
- selectmulti2: [ 'true', 'false' ],
- selectmulti3: [ 'false' ],
- selectmultioption1: [ 'false' ],
- selectmultioption2: [ 'true', 'false' ],
- selectmultioption3: [ 'false' ],
- autocompletion1: '',
- autocompletion1_autocompletion: '',
- autocompletion1_autocompletion_value_shown: '',
- autocompletion2: 'id2',
- autocompletion2_autocompletion: 'value2',
- autocompletion2_autocompletion_value_shown: 'value2',
- richtext1: '',
- richtext2: '<div>lalu <b>b</b> lalu</div>',
- richtext3: '',
- richtext4: '<div>lalu <i>b</i> lalu</div>',
- richtext5: '',
- richtext6: '<div>lalu <b>b</b> lalu</div>',
- richtext7: '',
- richtext8: '<div>lalu <i>b</i> lalu</div>',
- richtext9: '<div>lalu <b>b</b> lalu</div>',
- datetime1: '2015-01-11T12:40:00.000Z',
- datetime2: null,
- datetime3: '2015-01-11T12:40:00.000Z',
- datetime4: null,
- datetime5: '2015-01-11T12:40:00.000Z',
- date1: '2015-01-11',
- date2: null,
- date3: '2015-01-11',
- date4: null,
- date5: '2015-01-11',
- active1: true,
- active2: false,
- checkbox1: [],
- checkbox2: undefined,
- checkbox3: 'd',
- checkbox4: [],
- checkbox5: 'd',
- radiobox1: undefined,
- radiobox2: 'a',
- radiobox3: 'a',
- boolean1: true,
- boolean2: false,
- boolean3: true,
- boolean4: false,
- switch1: true,
- switch2: false,
- switch3: false,
- switch4: true,
- }
- assert.deepEqual(params, test_params, 'form param check 1')
- });
- QUnit.test("form defaults + params check", assert => {
- // assert.deepEqual(item, test.value, 'group set/get tests' );
- // mix default and params -> check it -> add note
- // test auto completion
- // show/hide fields base on field values -> bind changed event
- // form validation
- // form params check
- // add signature only if form_state is empty
- $('#qunit').append('<hr><h1>form defaults + params check</h1><form id="form3"></form>')
- var el = $('#form3')
- var defaults = {
- input1: '',
- password2: 'pw1234<l>',
- textarea2: 'lalu <l> lalu',
- select2: false,
- selectmulti2: [ false, true ],
- selectmultioption1: false,
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' },
- { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
- { name: 'password1', display: 'Password1', tag: 'input', type: 'password', limit: 100, null: false, default: 'some used pass' },
- { name: 'password2', display: 'Password2', tag: 'input', type: 'password', limit: 100, null: false, default: 'some not used pass' },
- { name: 'textarea1', display: 'Textarea1', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: 'some used text' },
- { name: 'textarea2', display: 'Textarea2', tag: 'textarea', rows: 6, limit: 100, null: false, upload: true, default: 'some not used text' },
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: false},
- { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: true },
- { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: [] },
- { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: true },
- ],
- },
- params: defaults,
- autofocus: true
- });
- assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
- assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
- // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
- assert.equal(el.find('[name="input2"]').val(), 'some used default', 'check input2 value')
- assert.equal(el.find('[name="input2"]').prop('required'), false, 'check input2 required')
- assert.equal(el.find('[name="password1"]').val(), 'some used pass', 'check password1 value')
- assert.equal(el.find('[name="password1_confirm"]').val(), 'some used pass', 'check password1 value')
- assert.equal(el.find('[name="password1"]').prop('required'), true, 'check password1 required')
- assert.equal(el.find('[name="password1"]').is(":focus"), false, 'check password1 focus')
- assert.equal(el.find('[name="password2"]').val(), 'pw1234<l>', 'check password2 value')
- assert.equal(el.find('[name="password2_confirm"]').val(), 'pw1234<l>', 'check password2 value')
- assert.equal(el.find('[name="password2"]').prop('required'), true, 'check password2 required')
- assert.equal(el.find('[name="password2"]').is(":focus"), false, 'check password2 focus')
- assert.equal(el.find('[name="textarea1"]').val(), 'some used text', 'check textarea1 value')
- assert.equal(el.find('[name="textarea1"]').prop('required'), true, 'check textarea1 required')
- assert.equal(el.find('[name="textarea1"]').is(":focus"), false, 'check textarea1 focus')
- assert.equal(el.find('[name="textarea2"]').val(), 'lalu <l> lalu', 'check textarea2 value')
- assert.equal(el.find('[name="textarea2"]').prop('required'), true, 'check textarea2 required')
- assert.equal(el.find('[name="textarea2"]').is(":focus"), false, 'check textarea2 focus')
- assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
- assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
- assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
- assert.equal(el.find('[name="select2"]').val(), 'false', 'check select2 value')
- assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
- assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
- assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
- assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
- });
- QUnit.test("form dependend fields check", assert => {
- // assert.deepEqual(item, test.value, 'group set/get tests' );
- // mix default and params -> check it -> add note
- // test auto completion
- // show/hide fields base on field values -> bind changed event
- // form validation
- // form params check
- // add signature only if form_state is empty
- $('#qunit').append('<hr><h1>form dependend fields check</h1><form id="form4"></form>')
- var el = $('#form4')
- var defaults = {
- input1: '',
- select2: false,
- selectmulti2: [ false, true ],
- selectmultioption1: false,
- datetime1: new Date(Date.parse('2015-01-11T12:40:00Z')),
- datetime3: new Date(Date.parse('2015-01-11T12:40:00Z')),
- date1: '2015-01-11',
- date3: '2015-01-11',
- }
- var form = new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' },
- { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
- { name: 'input3', display: 'Input3', tag: 'input', type: 'text', limit: 100, null: true, hide: true, default: 'some used default' },
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: false},
- { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { true: 'internal', false: 'public' }, default: true },
- { name: 'selectmulti2', display: 'SelectMulti2', tag: 'select', null: false, multiple: true, options: { true: 'internal', false: 'public' }, default: [] },
- { name: 'selectmultioption1', display: 'SelectMultiOption1', tag: 'select', null: true, multiple: true, options: [{ value: true, name: 'internal' }, { value: false, name: 'public' }], default: true },
- { name: 'datetime1', display: 'Datetime1', tag: 'datetime', null: true, default: defaults['datetime1'] },
- { name: 'datetime2', display: 'Datetime2', tag: 'datetime', null: true, default: defaults['datetime2'] },
- { name: 'datetime3', display: 'Datetime3', tag: 'datetime', null: false, default: defaults['datetime3'] },
- { name: 'datetime4', display: 'Datetime4', tag: 'datetime', null: false, default: defaults['datetime4'] },
- { name: 'date1', display: 'Date1', tag: 'date', null: true, default: defaults['date1'] },
- { name: 'date2', display: 'Date2', tag: 'date', null: true, default: defaults['date2'] },
- { name: 'date3', display: 'Date3', tag: 'date', null: false, default: defaults['date3'] },
- { name: 'date4', display: 'Date4', tag: 'date', null: false, default: defaults['date4'] },
- ],
- },
- params: defaults,
- dependency: [
- {
- bind: {
- name: 'select1',
- value: ["true"]
- },
- change: {
- name: 'input2',
- action: 'hide'
- },
- },
- {
- bind: {
- name: 'select1',
- value: ["true"]
- },
- change: {
- name: 'datetime1',
- action: 'hide'
- },
- },
- {
- bind: {
- name: 'select1',
- value: ["false"]
- },
- change: {
- name: 'input2',
- action: 'show'
- },
- },
- {
- bind: {
- name: 'select1',
- value: ["false"]
- },
- change: {
- name: 'datetime1',
- action: 'show'
- },
- },
- {
- bind: {
- name: 'select1',
- value: ["true"]
- },
- change: {
- name: 'input3',
- action: 'show'
- },
- },
- {
- bind: {
- name: 'select1',
- value: ["false"]
- },
- change: {
- name: 'input3',
- action: 'hide'
- },
- }
- ],
- autofocus: true
- });
- assert.equal(el.find('[name="input1"]').val(), '', 'check input1 value')
- assert.equal(el.find('[name="input1"]').prop('required'), false, 'check input1 required')
- // assert.equal(el.find('[name="input1"]').is(":focus"), true, 'check input1 focus')
- assert.equal(el.find('[name="input2"]').val(), 'some used default', 'check input2 value')
- assert.equal(el.find('[name="input2"]').prop('required'), false, 'check input2 required')
- assert.equal(el.find('[name="input3"]').val(), 'some used default', 'check input3 value')
- assert.equal(el.find('[name="input3"]').prop('required'), false, 'check input3 required')
- assert.equal(el.find('[name="select1"]').val(), 'false', 'check select1 value')
- assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
- assert.equal(el.find('[name="select1"]').is(":focus"), false, 'check select1 focus')
- assert.equal(el.find('[name="select2"]').val(), 'false', 'check select2 value')
- assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
- assert.equal(el.find('[name="select2"]').is(":focus"), false, 'check select2 focus')
- assert.equal(el.find('[name="selectmulti2"]').val()[0], 'true', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').val()[1], 'false', 'check selectmulti2 value')
- assert.equal(el.find('[name="selectmulti2"]').prop('required'), true, 'check selectmulti2 required')
- assert.equal(el.find('[name="selectmulti2"]').is(":focus"), false, 'check selectmulti2 focus')
- var params = App.ControllerForm.params(el)
- var test_params = {
- input1: "",
- input2: "some used default",
- input3: "some used default",
- select1: "false",
- select2: "false",
- selectmulti2: [ "true", "false" ],
- selectmultioption1: [ "false" ],
- datetime1: '2015-01-11T12:40:00.000Z',
- datetime2: null,
- datetime3: '2015-01-11T12:40:00.000Z',
- datetime4: null,
- date1: '2015-01-11',
- date2: null,
- date3: '2015-01-11',
- date4: null,
- }
- assert.deepEqual(params, test_params, 'form param check 2')
- errors = form.validate(params)
- test_errors = {
- datetime4: "is required",
- date4: "is required",
- }
- assert.deepEqual(errors, test_errors, 'validation errors check')
- App.ControllerForm.validate({ errors: errors, form: el })
- el.find('[name="select1"]').val('true')
- el.find('[name="select1"]').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- input1: "",
- input2: "some used default",
- input3: "some used default",
- select1: "true",
- select2: "false",
- selectmulti2: [ "true", "false" ],
- selectmultioption1: [ "false" ],
- datetime1: '2015-01-11T12:40:00.000Z',
- datetime2: null,
- datetime3: '2015-01-11T12:40:00.000Z',
- datetime4: null,
- date1: '2015-01-11',
- date2: null,
- date3: '2015-01-11',
- date4: null,
- }
- assert.deepEqual(params, test_params, 'form param check 3')
- });
- QUnit.test("form handler check with and without fieldset", assert => {
- // assert.deepEqual(item, test.value, 'group set/get tests' );
- // mix default and params -> check it -> add note
- // test auto completion
- // show/hide fields base on field values -> bind changed event
- // form validation
- // form params check
- // add signature only if form_state is empty
- $('#qunit').append('<hr><h1>form handler check with and without fieldset</h1><form id="form5"></form>')
- var el = $('#form5')
- var defaults = {
- select1: 'a',
- select2: '',
- }
- var formChanges = function(params, attribute, attributes, classname, form, ui) {
- //console.log('FROM', form)
- if (params['select1'] === 'b') {
- //console.log('select1 -> b', params)
- var item = {
- name: 'select2',
- display: 'Select2',
- tag: 'select',
- null: true,
- options: { 1:'1', 2:'2', 3:'3' },
- default: 3,
- };
- var newElement = ui.formGenItem(item, classname, form)
- form.find('[name="select2"]').closest('.form-group').replaceWith(newElement)
- }
- if (params['select1'] === 'a') {
- //console.log('select1 -> a', params)
- var item = {
- name: 'select2',
- display: 'Select2',
- tag: 'select',
- null: true,
- options: { 1:'1', 2:'2', 3:'3' },
- default: 1,
- };
- var newElement = ui.formGenItem(item, classname, form)
- form.find('[name="select2"]').closest('.form-group').replaceWith(newElement)
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { a: 'a', b: 'b' }, default: 'b'},
- { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { 1:'1', 2:'2', 3:'3' }, default: 2 },
- ],
- },
- params: defaults,
- handlers: [
- formChanges,
- ],
- //noFieldset: true,
- });
- assert.equal(el.find('[name="select1"]').val(), 'a', 'check select1 value')
- assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
- assert.equal(el.find('[name="select2"]').val(), '1', 'check select2 value')
- assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
- var params = App.ControllerForm.params(el)
- var test_params = {
- select1: 'a',
- select2: '1',
- }
- assert.deepEqual(params, test_params, 'form param check 4')
- el.find('[name="select1"]').val('b')
- el.find('[name="select1"]').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'b',
- select2: '3',
- }
- assert.deepEqual(params, test_params, 'form param check 5')
- el.find('[name="select1"]').val('a')
- el.find('[name="select1"]').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'a',
- select2: '1',
- }
- assert.deepEqual(params, test_params, 'form param check 6')
- // test with noFieldset
- el.empty()
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { a: 'a', b: 'b' }, default: 'b'},
- { name: 'select2', display: 'Select2', tag: 'select', null: true, options: { 1:'1', 2:'2', 3:'3' }, default: 2 },
- ],
- },
- params: defaults,
- handlers: [
- formChanges,
- ],
- noFieldset: true,
- });
- assert.equal(el.find('[name="select1"]').val(), 'a', 'check select1 value')
- assert.equal(el.find('[name="select1"]').prop('required'), false, 'check select1 required')
- assert.equal(el.find('[name="select2"]').val(), '1', 'check select2 value')
- assert.equal(el.find('[name="select2"]').prop('required'), false, 'check select2 required')
- var params = App.ControllerForm.params(el)
- var test_params = {
- select1: 'a',
- select2: '1',
- }
- assert.deepEqual(params, test_params, 'form param check 7')
- el.find('[name="select1"]').val('b')
- el.find('[name="select1"]').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'b',
- select2: '3',
- }
- assert.deepEqual(params, test_params, 'form param check 8')
- el.find('[name="select1"]').val('a')
- el.find('[name="select1"]').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'a',
- select2: '1',
- }
- assert.deepEqual(params, test_params, 'form param check 9')
- });
- QUnit.test("form postmaster filter", assert => {
- App.TicketPriority.refresh([
- {
- id: 1,
- name: 'prio 1',
- },
- {
- id: 2,
- name: 'prio 2',
- },
- ] )
- App.Group.refresh([
- {
- id: 1,
- name: 'group 1',
- },
- {
- id: 2,
- name: 'group 2',
- },
- ] )
- $('#qunit').append('<hr><h1>form postmaster filter</h1><form id="form6"></form>')
- var el = $('#form6')
- var defaults = {
- input2: 'some name',
- match: {
- from: {
- operator: 'contains',
- value: 'some@address',
- },
- subject: {
- operator: 'contains',
- value: 'some subject',
- },
- cc: {
- operator: 'starts with one of',
- value: ['a', 'b', 'c'],
- },
- },
- set: {
- 'x-zammad-ticket-customer_id': {
- value: 'customer',
- value_completion: ''
- },
- 'x-zammad-ticket-group_id': {
- value: '1'
- },
- 'x-zammad-ticket-owner_id': {
- value: 'owner',
- value_completion: ''
- },
- 'x-zammad-ticket-priority_id': {
- value: '1'
- },
- 'x-zammad-ticket-tags': {
- operator: 'add',
- value: 'test, test1'
- }
- },
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default' },
- { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
- { name: 'match', display: 'Match', tag: 'postmaster_match', null: false, default: false},
- { name: 'set', display: 'Set', tag: 'postmaster_set', null: false, default: false, user_action: false},
- ],
- },
- params: defaults,
- });
- params = App.ControllerForm.params(el)
- test_params = {
- input1: 'some not used default',
- input2: 'some name',
- match: {
- from: {
- operator: 'contains',
- value: 'some@address'
- },
- subject: {
- operator: 'contains',
- value: 'some subject'
- },
- cc: {
- operator: 'starts with one of',
- value: ['a', 'b', 'c'],
- },
- },
- set: {
- 'x-zammad-ticket-customer_id': {
- value: 'customer',
- value_completion: ''
- },
- 'x-zammad-ticket-group_id': {
- value: '1'
- },
- 'x-zammad-ticket-owner_id': {
- value: 'owner',
- value_completion: ''
- },
- 'x-zammad-ticket-priority_id': {
- value: '1'
- },
- 'x-zammad-ticket-tags': {
- operator: 'add',
- value: 'test, test1'
- }
- },
- };
- assert.deepEqual(params, test_params, 'form param check 10')
- el.find('[name="set::x-zammad-ticket-priority_id::value"]').closest('.js-filterElement').find('.js-remove').trigger('click')
- el.find('[name="set::x-zammad-ticket-customer_id::value"]').closest('.js-filterElement').find('.js-remove').trigger('click')
- params = App.ControllerForm.params(el)
- test_params = {
- input1: 'some not used default',
- input2: 'some name',
- match: {
- from: {
- operator: 'contains',
- value: 'some@address'
- },
- subject: {
- operator: 'contains',
- value: 'some subject'
- },
- cc: {
- operator: 'starts with one of',
- value: ['a', 'b', 'c'],
- },
- },
- set: {
- 'x-zammad-ticket-owner_id': {
- value: 'owner',
- value_completion: ''
- },
- 'x-zammad-ticket-group_id': {
- value: '1'
- },
- 'x-zammad-ticket-tags': {
- operator: 'add',
- value: 'test, test1'
- },
- },
- };
- assert.deepEqual(params, test_params, 'form param check 11')
- el.find('.postmaster_set .js-filterElement').last().find('.filter-controls .js-add').trigger('click')
- params = App.ControllerForm.params(el)
- test_params = {
- input1: 'some not used default',
- input2: 'some name',
- match: {
- from: {
- operator: 'contains',
- value: 'some@address'
- },
- subject: {
- operator: 'contains',
- value: 'some subject'
- },
- cc: {
- operator: 'starts with one of',
- value: ['a', 'b', 'c'],
- },
- },
- set: {
- 'x-zammad-ticket-owner_id': {
- value: 'owner',
- value_completion: ''
- },
- 'x-zammad-ticket-group_id': {
- value: '1'
- },
- 'x-zammad-ticket-tags': {
- operator: 'add',
- value: 'test, test1'
- },
- 'x-zammad-ticket-title': {
- value: ''
- },
- },
- };
- assert.deepEqual(params, test_params, 'form param check 12')
- App.Delay.set(function() {
- QUnit.test("form postmaster filter - needed to do delayed because of tag ui", assert => {
- el.find('[name="set::x-zammad-ticket-tags::value"]').closest('.js-filterElement').find('.token .close').last().trigger('click')
- params = App.ControllerForm.params(el)
- test_params = {
- input1: 'some not used default',
- input2: 'some name',
- match: {
- from: {
- operator: 'contains',
- value: 'some@address'
- },
- subject: {
- operator: 'contains',
- value: 'some subject'
- },
- cc: {
- operator: 'starts with one of',
- value: ['a', 'b', 'c'],
- },
- },
- set: {
- 'x-zammad-ticket-owner_id': {
- value: 'owner',
- value_completion: ''
- },
- 'x-zammad-ticket-group_id': {
- value: '1'
- },
- 'x-zammad-ticket-priority_id': {
- value: '1'
- },
- 'x-zammad-ticket-tags': {
- operator: 'add',
- value: 'test'
- },
- },
- };
- assert.deepEqual(params, test_params, 'form param check 13')
- })
- }, 500);
- });
- QUnit.test("form selector", assert => {
- $('#qunit').append('<hr><h1>form selector</h1><div><form id="form7"></form></div>')
- var el = $('#form7')
- var defaults = {
- input2: 'some name66',
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default33' },
- { name: 'input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
- ],
- },
- params: defaults,
- });
- test_params = {
- input1: 'some not used default33',
- input2: 'some name66',
- };
- params = App.ControllerForm.params(el)
- assert.deepEqual(params, test_params, 'form param check 14 via $("#form")')
- params = App.ControllerForm.params(el.find('input'))
- assert.deepEqual(params, test_params, 'form param check 15 via $("#form").find("input")')
- params = App.ControllerForm.params(el.parent())
- assert.deepEqual(params, test_params, 'form param check 16 via $("#form").parent()')
- });
- QUnit.test("form params check 2", assert => {
- $('#qunit').append('<hr><h1>form params check</h1><form id="form9"></form>')
- var el = $('#form9')
- var defaults = {
- select1: false,
- select2: true,
- select3: null,
- select4: undefined,
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, options: { true: 'internal', false: 'public' } },
- { name: 'select2', display: 'Select2', tag: 'select', null: false, options: { true: 'internal', false: 'public' } },
- { name: 'select3', display: 'Select3', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select3' } },
- { name: 'select4', display: 'Select4', tag: 'select', null: false, nulloption: true, options: { aa: 'aa', bb: 'bb', select3: 'select4' } },
- ],
- },
- params: defaults,
- autofocus: true
- });
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'false',
- select2: 'true',
- select3: '',
- select4: '',
- }
- //console.log('params', params)
- //console.log('test_params', test_params)
- assert.deepEqual(params, test_params, 'form param check 17')
- });
- QUnit.test("form params check direct", assert => {
- $('#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>')
- var el = $('#form10')
- params = App.ControllerForm.params(el)
- test_params = {
- a: 'b',
- l: {
- l: {
- l1: 'd',
- '': '',
- },
- },
- f: {
- f: {
- f1: 'e',
- '': '',
- },
- },
- }
- //console.log('params', params)
- //console.log('test_params', test_params)
- assert.deepEqual(params, test_params, 'form param check 18')
- });
- QUnit.test("object manager form 1", assert => {
- $('#qunit').append('<hr><h1>object manager 1</h1><form id="form11"></form>')
- var el = $('#form11')
- var defaults = {}
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
- ],
- },
- params: $.extend(defaults, { object: 'Ticket' }),
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- data_option: {
- default: "",
- linktemplate: "",
- maxlength: 120,
- type: "text"
- },
- data_type: "input",
- screens: {
- create_middle: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: true,
- required: false,
- }
- },
- edit: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: true,
- required: false,
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 19')
- el.find('[name=data_type]').val('datetime').trigger('change')
- params = App.ControllerForm.params(el)
- var test_params = {
- data_option: {
- diff: null,
- future: true,
- past: true
- },
- data_type: "datetime",
- screens: {
- create_middle: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: true,
- required: false,
- }
- },
- edit: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: true,
- required: false,
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 20')
- });
- QUnit.test("object manager form 2", assert => {
- $('#qunit').append('<hr><h1>object manager 2</h1><form id="form12"></form>')
- var el = $('#form12')
- var defaults = {
- id: 123,
- data_option: {
- default: "",
- maxlength: 120,
- type: "text"
- },
- data_type: "input",
- screens: {
- create_middle: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- },
- edit: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
- ],
- },
- params: $.extend(defaults, { object: 'Ticket' }),
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- data_option: {
- default: "",
- linktemplate: "",
- maxlength: 120,
- type: "text"
- },
- data_type: "input",
- screens: {
- create_middle: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: false,
- required: false,
- }
- },
- edit: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: false,
- required: false,
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 21')
- });
- QUnit.test("object manager form 3", assert => {
- $('#qunit').append('<hr><h1>object manager 3</h1><form id="form13"></form>')
- var el = $('#form13')
- var defaults = {}
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
- ],
- },
- params: $.extend(defaults, { object: 'Ticket' }),
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- data_option: {
- default: "",
- linktemplate: "",
- maxlength: 120,
- type: "text"
- },
- data_type: "input",
- screens: {
- create_middle: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: true,
- required: false,
- }
- },
- edit: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: true,
- required: false,
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 22')
- el.find('[name="screens::create_middle::ticket.customer::shown"]').trigger('click')
- el.find('[name="screens::edit::ticket.customer::shown"]').trigger('click')
- params = App.ControllerForm.params(el)
- test_params = {
- data_option: {
- default: "",
- linktemplate: "",
- maxlength: 120,
- type: "text"
- },
- data_type: "input",
- screens: {
- create_middle: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: false,
- required: false,
- }
- },
- edit: {
- "ticket.agent": {
- shown: true,
- required: false,
- },
- "ticket.customer": {
- shown: false,
- required: false,
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 23')
- });
- QUnit.test("check if select value is not existing but is shown", assert => {
- $('#qunit').append('<hr><h1>check if select value is not existing but is shown</h1><form id="form17"></form>')
- var el = $('#form17')
- var defaults = {
- select1: 'NOT EXISTING',
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
- ],
- },
- params: defaults,
- });
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'NOT EXISTING',
- }
- assert.deepEqual(params, test_params)
- assert.equal('AA', el.find('[name=select1] option')[0].text)
- assert.equal('äöü', el.find('[name=select1] option')[1].text)
- assert.equal('b', el.find('[name=select1] option')[2].text)
- assert.equal('B', el.find('[name=select1] option')[3].text)
- assert.equal('NOT EXISTING', el.find('[name=select1] option')[4].text)
- assert.equal('XX', el.find('[name=select1] option')[5].text)
- });
- QUnit.test("check if select value is not existing and is not shown", assert => {
- $('#qunit').append('<hr><h1>check if select value is not existing and is not shown</h1><form id="form18"></form>')
- var el = $('#form18')
- var defaults = {
- select1: 'NOT EXISTING',
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
- ],
- },
- params: defaults,
- rejectNonExistentValues: true,
- });
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'XY',
- }
- assert.deepEqual(params, test_params)
- assert.equal('AA', el.find('[name=select1] option')[0].text)
- assert.equal('äöü', el.find('[name=select1] option')[1].text)
- assert.equal('b', el.find('[name=select1] option')[2].text)
- assert.equal('B', el.find('[name=select1] option')[3].text)
- assert.equal('XX', el.find('[name=select1] option')[4].text)
- });
- QUnit.test("time range form 1", assert => {
- $('#qunit').append('<hr><h1>time range form 1</h1><form id="form14"></form>')
- var el = $('#form14')
- var defaults = {}
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'time_range', display: 'Format', tag: 'time_range', null: false },
- ],
- },
- params: $.extend(defaults, { object: 'Ticket' }),
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- "time_range": {
- "range": "minute",
- "value": "1"
- }
- }
- assert.deepEqual(params, test_params, 'base form param range check')
- el.find('.js-range').val('minute').trigger('change')
- el.find('.js-valueRangeSelector .js-value').val('120').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "minute",
- "value": "120"
- }
- }
- assert.deepEqual(params, test_params, 'form param minute range check')
- el.find('.js-range').val('hour').trigger('change')
- el.find('.js-valueRangeSelector .js-value').val('48').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "hour",
- "value": "48"
- }
- }
- assert.deepEqual(params, test_params, 'form param hour range check')
- el.find('.js-range').val('day').trigger('change')
- el.find('.js-valueRangeSelector .js-value').val('31').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "day",
- "value": "31"
- }
- }
- assert.deepEqual(params, test_params, 'form param day range check')
- el.find('.js-range').val('month').trigger('change')
- el.find('.js-valueRangeSelector .js-value').val('12').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "month",
- "value": "12"
- }
- }
- assert.deepEqual(params, test_params, 'form param month range check')
- el.find('.js-range').val('year').trigger('change')
- el.find('.js-valueRangeSelector .js-value').val('20').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "year",
- "value": "20"
- }
- }
- assert.deepEqual(params, test_params, 'form param year range check')
- el.find('.js-range').val('minute').trigger('change')
- el.find('.js-valueRangeSelector .js-value').val('11').trigger('change')
- el.find('.js-range').val('hour').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "hour",
- "value": "11"
- }
- }
- assert.deepEqual(params, test_params, 'form param selected value hour check')
- el.find('.js-range').val('day').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "day",
- "value": "11"
- }
- }
- assert.deepEqual(params, test_params, 'form param selected value day check')
- el.find('.js-range').val('month').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "month",
- "value": "11"
- }
- }
- assert.deepEqual(params, test_params, 'form param selected value month check')
- el.find('.js-range').val('year').trigger('change')
- params = App.ControllerForm.params(el)
- test_params = {
- "time_range": {
- "range": "year",
- "value": "11"
- }
- }
- assert.deepEqual(params, test_params, 'form param selected value year check')
- });
- QUnit.test("form select with empty option list", assert => {
- $('#qunit').append('<hr><h1>form select with empty option list</h1><form id="form15"></form>')
- var el = $('#form15')
- var defaults = {}
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, default: '', options: {}, relation: '', maxlength: 255 },
- { name: 'select2', display: 'Select2', tag: 'select', null: true, default: '', options: {}, relation: '', maxlength: 255, nulloption: true },
- { name: 'select3', display: 'Select3', tag: 'select', null: true, default: '', options: { undefined: 'A', null: 'B'} },
- { name: 'select4', display: 'Select4', tag: 'select', null: true, default: '', options: { 'A': undefined, 'B': null} },
- { name: 'select5', display: 'Select5', tag: 'select', null: true, default: 'A', options: { 'A': undefined, 'B': null} },
- { name: 'select6', display: 'Select6', tag: 'select', null: true, default: undefined, options: { 'A': undefined, 'B': null} },
- ],
- },
- params: defaults,
- autofocus: true
- });
- params = App.ControllerForm.params(el)
- test_params = {
- select2: '',
- select3: 'undefined',
- select4: 'B',
- select5: 'A',
- select6: 'B',
- }
- assert.deepEqual(params, test_params)
- });
- QUnit.test("form elements with sort check", assert => {
- $('#qunit').append('<hr><h1>form elements with sort check</h1><form id="form16"></form>')
- var el = $('#form16')
- var defaults = {}
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'select1', display: 'Select1', tag: 'select', null: true, default: 'XY', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
- { name: 'checkbox1', display: 'Checkbox1', tag: 'checkbox', null: false, default: 'A', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
- { name: 'radio1', display: 'Radio1', tag: 'radio', null: false, default: 'A', options: { 'XX': 'AA', 'A': 'XX', 'B': 'B', 'XY': 'b', '': 'äöü' } },
- ],
- },
- params: defaults,
- autofocus: true
- });
- params = App.ControllerForm.params(el)
- test_params = {
- select1: 'XY',
- checkbox1: 'A',
- radio1: 'A',
- }
- assert.deepEqual(params, test_params)
- assert.equal('AA', el.find('[name=select1] option')[0].text)
- assert.equal('äöü', el.find('[name=select1] option')[1].text)
- assert.equal('b', el.find('[name=select1] option')[2].text)
- assert.equal('B', el.find('[name=select1] option')[3].text)
- assert.equal('XX', el.find('[name=select1] option')[4].text)
- assert.equal('XX', el.find('[name=checkbox1]')[0].value)
- assert.equal('', el.find('[name=checkbox1]')[1].value)
- assert.equal('XY', el.find('[name=checkbox1]')[2].value)
- assert.equal('B', el.find('[name=checkbox1]')[3].value)
- assert.equal('A', el.find('[name=checkbox1]')[4].value)
- assert.equal('XX', el.find('[name=radio1]')[0].value)
- assert.equal('', el.find('[name=radio1]')[1].value)
- assert.equal('XY', el.find('[name=radio1]')[2].value)
- assert.equal('B', el.find('[name=radio1]')[3].value)
- assert.equal('A', el.find('[name=radio1]')[4].value)
- });
- QUnit.test("form deep nesting", assert => {
- $('#qunit').append('<hr><h1>form selector</h1><div><form id="form19"></form></div>')
- var el = $('#form19')
- var defaults = {
- a: {
- input1: 'a'
- },
- b: {
- c: {
- input2: 'b'
- }
- }
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'a::input1', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, default: 'some not used default33' },
- { name: 'b::c::input2', display: 'Input2', tag: 'input', type: 'text', limit: 100, null: true, default: 'some used default' },
- ],
- },
- params: defaults,
- });
- params = App.ControllerForm.params(el)
- assert.deepEqual(params, defaults, 'nested params')
- });
- QUnit.test("form with external links", assert => {
- $('#qunit').append('<hr><h1>form with external links</h1><div><form id="form20"></form></div>')
- var el = $('#form20')
- var defaults = {
- a: '133',
- b: 'abc d',
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'a', display: 'Input1', tag: 'input', type: 'text', limit: 100, null: true, linktemplate: "https://example.com/?q=#{ticket.a}" },
- { name: 'b', display: 'Select1', tag: 'select', type: 'text', options: { a: 1, b: 2 }, limit: 100, null: true, linktemplate: "https://example.com/?q=#{ticket.b}" },
- ],
- className: 'Ticket',
- },
- params: defaults,
- });
- params = App.ControllerForm.params(el)
- assert.deepEqual(params, defaults)
- assert.equal('https://example.com/?q=133', el.find('input[name="a"]').parents('.controls').find('a[href]').attr('href'))
- assert.equal('https://example.com/?q=abc%20d', el.find('select[name="b"]').parents('.controls').find('a[href]').attr('href'))
- });
- QUnit.test("Fixes #4024 - Tree select value cannot be set to \"-\" (empty) with Trigger/Scheduler/Core workflow.", assert => {
- $('#qunit').append('<hr><h1>Fixes #4024 - Tree select value cannot be set to "-" (empty) with Trigger/Scheduler/Core workflow.</h1><form id="form22"></form>')
- var el = $('#form22')
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: '4024_select', display: '4024_select', tag: 'select_search', null: true, nulloption: true, multiple: true, options: { 'a': 'a', 'b': 'b' } },
- { name: '4024_multiselect', display: '4024_multiselect', tag: 'multiselect_search', null: true, nulloption: true, multiple: true, options: { 'a': 'a', 'b': 'b' } },
- { 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'}] },
- { 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'}] },
- ],
- },
- autofocus: true
- });
- assert.equal(el.find('select[name="4024_select"] option[value=""]').text(), '-', '4024_select has nulloption')
- assert.equal(el.find('select[name="4024_multiselect"] option[value=""]').text(), '-', '4024_multiselect has nulloption')
- 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')
- 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')
- });
- QUnit.test("Fixes #4027 - undefined method `to_hash` on editing select fields in the admin interface after migration to 5.1.", assert => {
- $('#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>')
- var el = $('#form23')
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { 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' } },
- { 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' } },
- { 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' } },
- { 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' } },
- { 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' } },
- ],
- },
- autofocus: true
- });
- assert.equal(el.find('select[name="4027_selcet_hash"] option[selected]').text(), 'C', '4027_select has historic text')
- assert.equal(el.find('select[name="4027_selcet_array"] option[selected]').text(), 'C', '4027_selcet_array has historic text')
- assert.equal(el.find('select[name="4027_multiselect_hash"] option[selected]').text(), 'C', '4027_multiselect_hash has historic text')
- assert.equal(el.find('select[name="4027_multiselect_array"] option[selected]').text(), 'CD', '4027_multiselect_array has historic text')
- assert.equal(el.find('div[data-attribute-name="4027_tree_select_array"] .js-input').val(), 'C', '4027_tree_select_array has historic text')
- });
- QUnit.test("object manager form 4", assert => {
- $('#qunit').append('<hr><h1>object manager 1</h1><form id="form21"></form>')
- var el = $('#form21')
- var defaults = {
- data_type: 'select'
- }
- new App.ControllerForm({
- el: el,
- model: {
- configure_attributes: [
- { name: 'data_type', display: 'Format', tag: 'object_manager_attribute', null: false },
- ],
- },
- params: $.extend(defaults, { object: 'Ticket' }),
- autofocus: true
- });
- var params = App.ControllerForm.params(el)
- var test_params = {
- "data_option": {
- "customsort": undefined,
- "default": undefined,
- "linktemplate": "",
- "translate": false
- },
- "data_type": "select",
- "screens": {
- "create_middle": {
- "ticket.agent": {
- "required": false,
- "shown": true
- },
- "ticket.customer": {
- "required": false,
- "shown": true
- }
- },
- "edit": {
- "ticket.agent": {
- "required": false,
- "shown": true
- },
- "ticket.customer": {
- "required": false,
- "shown": true
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 21')
- $("#form21 select[name='data_option::translate']").val('true')
- var params = App.ControllerForm.params(el)
- var test_params = {
- "data_option": {
- "customsort": undefined,
- "default": undefined,
- "linktemplate": "",
- "translate": true
- },
- "data_type": "select",
- "screens": {
- "create_middle": {
- "ticket.agent": {
- "required": false,
- "shown": true
- },
- "ticket.customer": {
- "required": false,
- "shown": true
- }
- },
- "edit": {
- "ticket.agent": {
- "required": false,
- "shown": true
- },
- "ticket.customer": {
- "required": false,
- "shown": true
- }
- }
- }
- }
- assert.deepEqual(params, test_params, 'form param check 21')
- })
|