form_find.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // form
  2. QUnit.test( "find form check", assert => {
  3. $('#forms').append('<hr><h1>find form check</h1><form id="form1"></form>')
  4. var form1 = App.ControllerForm.findForm($('#form1'))
  5. assert.equal(form1.is('form'), true)
  6. $('#forms').append('<hr><h1>find form check</h1><form id="form2"><input class="js-input" value="test 123"></form>')
  7. var form2 = App.ControllerForm.findForm($('#form2 .js-input'))
  8. assert.equal(form2.is('form'), true)
  9. $('#forms').append('<hr><h1>find form check</h1><form id="form3"><input class="js-input" value="test 123"><button class="js-button">text</button></form>')
  10. var form3 = App.ControllerForm.findForm($('#form3 .js-button'))
  11. assert.equal(form3.is('form'), true)
  12. App.ControllerForm.disable($('#form3 .js-button'))
  13. assert.equal($('#form3 .js-button').prop('readonly'), true)
  14. assert.equal($('#form3 .js-button').prop('disabled'), true)
  15. assert.equal($('#form3 .js-input').prop('readonly'), true)
  16. assert.equal($('#form3 .js-input').prop('disabled'), false)
  17. App.ControllerForm.enable($('#form3 .js-button'))
  18. assert.equal($('#form3 .js-button').prop('readonly'), false)
  19. assert.equal($('#form3 .js-button').prop('disabled'), false)
  20. assert.equal($('#form3 .js-input').prop('readonly'), false)
  21. assert.equal($('#form3 .js-input').prop('disabled'), false)
  22. $('#forms').append('<hr><h1>find form check by only disable button</h1><form id="form31"><input class="js-input" value="test 123"><button class="js-button">text</button></form>')
  23. var form31 = App.ControllerForm.findForm($('#form31 .js-button'))
  24. App.ControllerForm.disable($('#form31 .js-button'), 'button')
  25. assert.equal($('#form31 .js-button').prop('readonly'), true)
  26. assert.equal($('#form31 .js-button').prop('disabled'), true)
  27. assert.equal($('#form31 .js-input').prop('readonly'), false)
  28. assert.equal($('#form31 .js-input').prop('disabled'), false)
  29. App.ControllerForm.enable($('#form31 .js-button'))
  30. assert.equal($('#form31 .js-button').prop('readonly'), false)
  31. assert.equal($('#form31 .js-button').prop('disabled'), false)
  32. assert.equal($('#form31 .js-input').prop('readonly'), false)
  33. assert.equal($('#form31 .js-input').prop('disabled'), false)
  34. $('#forms').append('<hr><h1>find form check</h1><div id="form4"><input class="js-input" value="test 123"><button class="js-button">text</button></div>')
  35. var form4 = App.ControllerForm.findForm($('#form4 .js-button'))
  36. assert.equal(form4.is('form'), false)
  37. App.ControllerForm.disable($('#form4 .js-button'))
  38. assert.equal($('#form4 .js-button').prop('readonly'), true)
  39. assert.equal($('#form4 .js-button').prop('disabled'), true)
  40. assert.equal($('#form4 .js-input').prop('readonly'), false)
  41. assert.equal($('#form4 .js-input').prop('disabled'), false)
  42. App.ControllerForm.enable($('#form4 .js-button'))
  43. assert.equal($('#form4 .js-button').prop('readonly'), false)
  44. assert.equal($('#form4 .js-button').prop('disabled'), false)
  45. assert.equal($('#form4 .js-input').prop('readonly'), false)
  46. assert.equal($('#form4 .js-input').prop('disabled'), false)
  47. });