form_searchable_select.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // searchable_select
  2. test( "searchable_select check", function() {
  3. $('#forms').append('<hr><h1>searchable_select check</h1><form id="form1"></form>')
  4. var el = $('#form1')
  5. var defaults = {
  6. searchable_select2: 'bbb',
  7. }
  8. var options = {
  9. 'aaa': 'aaa display',
  10. 'bbb': 'bbb display',
  11. 'ccc': 'ccc display',
  12. }
  13. new App.ControllerForm({
  14. el: el,
  15. model: {
  16. configure_attributes: [
  17. { name: 'searchable_select1', display: 'SearchableSelect1', tag: 'searchable_select', options: options, null: true, default: defaults['searchable_select1'] },
  18. { name: 'searchable_select2', display: 'SearchableSelect2', tag: 'searchable_select', options: options, null: false, default: defaults['searchable_select2'] },
  19. ]
  20. },
  21. autofocus: true
  22. })
  23. var params = App.ControllerForm.params( el )
  24. var test_params = {
  25. searchable_select1: '',
  26. searchable_select2: 'bbb',
  27. }
  28. deepEqual( params, test_params, 'form param check' )
  29. // change selection
  30. $('[name="searchable_select1"].js-shadow + .js-input').focus().val('').trigger('input')
  31. var entries = $('[name="searchable_select1"]').closest('.searchableSelect').find('.js-optionsList li:not(.is-hidden)').length
  32. equal(entries, 3, 'dropdown count')
  33. $('[name="searchable_select1"].js-shadow + .js-input').focus().val('ccc display').trigger('input')
  34. var entries = $('[name="searchable_select1"]').closest('.searchableSelect').find('.js-optionsList li:not(.is-hidden)').length
  35. equal(entries, 1, 'dropdown count')
  36. $('[name="searchable_select1"]').closest('.searchableSelect').find('.js-optionsList li:not(.is-hidden)').first().click()
  37. params = App.ControllerForm.params( el )
  38. test_params = {
  39. searchable_select1: 'ccc',
  40. searchable_select2: 'bbb',
  41. }
  42. deepEqual( params, test_params, 'form param check' )
  43. $('[name="searchable_select2"].js-shadow + .js-input').focus().val('').trigger('input')
  44. var entries = $('[name="searchable_select2"]').closest('.searchableSelect').find('.js-optionsList li:not(.is-hidden)').length
  45. equal(entries, 3, 'dropdown count')
  46. $('[name="searchable_select2"].js-shadow + .js-input').focus().val('ccc display').trigger('input')
  47. var entries = $('[name="searchable_select2"]').closest('.searchableSelect').find('.js-optionsList li:not(.is-hidden)').length
  48. equal(entries, 1, 'dropdown count')
  49. $('[name="searchable_select2"]').closest('.searchableSelect').find('.js-optionsList li:not(.is-hidden)').first().click()
  50. params = App.ControllerForm.params( el )
  51. test_params = {
  52. searchable_select1: 'ccc',
  53. searchable_select2: 'ccc',
  54. }
  55. deepEqual( params, test_params, 'form param check' )
  56. });