form_column_select.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // column_select
  2. test( "column_select check", function(assert) {
  3. $('#forms').append('<hr><h1>column_select check</h1><form id="form1"></form>')
  4. var el = $('#form1')
  5. var defaults = {
  6. column_select2: ['aaa', 'bbb'],
  7. column_select3: [1, '2'],
  8. }
  9. var options = {
  10. 'aaa': 'aaa display',
  11. 'bbb': 'bbb display',
  12. 'ccc': 'ccc display',
  13. 1: '1 display',
  14. '2': '2 display',
  15. }
  16. new App.ControllerForm({
  17. el: el,
  18. model: {
  19. configure_attributes: [
  20. { name: 'column_select1', display: 'ColumnSelect1', tag: 'column_select', options: options, null: true, default: defaults['column_select1'] },
  21. { name: 'column_select2', display: 'ColumnSelect2', tag: 'column_select', options: options, null: false, default: defaults['column_select2'] },
  22. { name: 'column_select3', display: 'ColumnSelect3', tag: 'column_select', options: options, null: false, default: defaults['column_select3'] },
  23. ]
  24. },
  25. autofocus: true
  26. })
  27. var params = App.ControllerForm.params(el)
  28. var test_params = {
  29. column_select2: ['aaa', 'bbb'],
  30. column_select3: ['1', '2'],
  31. }
  32. deepEqual(params, test_params, 'form param check')
  33. // add and remove selections
  34. $('[data-name="column_select1"] .js-pool .js-option[data-value="bbb"]').click()
  35. params = App.ControllerForm.params(el)
  36. test_params = {
  37. column_select1: 'bbb',
  38. column_select2: ['aaa', 'bbb'],
  39. column_select3: ['1', '2'],
  40. }
  41. deepEqual(params, test_params, 'form param check')
  42. var done = assert.async();
  43. setTimeout(function() {
  44. $('[data-name="column_select1"] .js-pool .js-option[data-value="aaa"]').click()
  45. $('[data-name="column_select2"] .js-pool .js-option[data-value="1"]').click()
  46. $('[data-name="column_select2"].js-selected .js-option[data-value="aaa"]').click()
  47. $('[data-name="column_select3"] .js-pool .js-option[data-value="aaa"]').click()
  48. params = App.ControllerForm.params(el)
  49. test_params = {
  50. column_select1: ['aaa', 'bbb'],
  51. column_select2: ['1', 'bbb'],
  52. column_select3: ['1', '2', 'aaa'],
  53. }
  54. deepEqual(params, test_params, 'form param check')
  55. done();
  56. }, 400);
  57. });