yvanui.searchbox.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * YvanUI
  3. *
  4. * Copyright (c) 2018 www.yvanui.com. All rights reserved.
  5. * @author luoyifan@qq.com
  6. * @time 2019-02-25 17:19:00
  7. */
  8. (function ($) {
  9. $.extend($.fn.searchbox.methods, {
  10. onSysRender: function (target) {
  11. var $me = $(target);
  12. $me.textbox('textbox').focus(function () {
  13. if (!$me.data().isWidgetOpen) {
  14. var v = $me.textbox('getValue');
  15. $me.data().widgetValue = v;
  16. if ($.trim(v).length > 0) {
  17. console.log('setWidgetValue-notNull', v);
  18. } else {
  19. console.log('setWidgetValue-null', v);
  20. }
  21. }
  22. });
  23. $me.textbox('textbox').blur(function () {
  24. if (!$me.data().isWidgetOpen) {
  25. $me.data().widgetTmpValue = $me.textbox('getValue');
  26. console.log('setWidgetTmpValue', $me.data().widgetTmpValue);
  27. if ($me.data().widgetValue === $me.data().widgetTmpValue) {
  28. //值没有被修改
  29. return;
  30. }
  31. //值被改了,需要触发弹出
  32. //$me.searchbox('options').searcher.call($me[0]);
  33. //值被改了,需要被还原
  34. // $me.textbox('setValue', $me.data().widgetValue);
  35. } else {
  36. console.log('setWidgetTmpValue-igorn', $me.textbox('getValue'));
  37. }
  38. });
  39. }
  40. });
  41. $.extend(true, $.fn.searchbox.defaults, {
  42. inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
  43. keydown: function (e) {
  44. if (e.keyCode === 13) {
  45. //需要强制触发一次 blur 事件
  46. e.preventDefault();
  47. var t = $(e.data.target);
  48. //先传值,避免出现搜索"回车搜索"的问题,也避免回车搜索无法清除上此搜索的结果
  49. t.searchbox("setValue", $(this).val());
  50. t.textbox('textbox').blur();
  51. var opts = t.searchbox("options");
  52. opts.searcher.call(e.data.target, t.searchbox("getValue"), t.searchbox("getName"));
  53. return false;
  54. }
  55. }
  56. })
  57. /*
  58. onBeforeValidate: function () {
  59. console.log('onBeforeValidate', $(this).val(), this, arguments);
  60. return false;
  61. },
  62. onValidate: function (valid) {
  63. //$(this).data().searchbox.widgetTmpValue = $(this).textbox('textbox').val();
  64. console.log('onValidate', $(this).val(), this, arguments);
  65. //var v = $(this).textbox('textbox').val();
  66. //$(this).searchbox('setWidgetTmpValue', v);
  67. return false;
  68. },
  69. onChange: function (newValue, oldValue) {
  70. //无论什么情况下,都直接返回编辑前的值
  71. var v = $(this).searchbox('getWidgetValue');
  72. if ($.type(v) === 'undefined') {
  73. v = '';
  74. }
  75. $(this).searchbox('initValue', v);
  76. console.log('onChange', $(this).val(), this, arguments);
  77. return false;
  78. }
  79. */
  80. //onChange: function (newValue, oldValue) {
  81. // var v1 = document.activeElement;
  82. // var v2 = $(this).textbox('textbox');
  83. // console.log(v1 === v2 ? 'onChange-F-yes' : 'onChange-F-no');
  84. //}
  85. });
  86. })(jQuery);