123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /**
- * YvanUI
- *
- * Copyright (c) 2018 www.yvanui.com. All rights reserved.
- * @author luoyifan@qq.com
- * @time 2019-02-25 17:19:00
- */
- (function ($) {
- $.extend($.fn.searchbox.methods, {
- onSysRender: function (target) {
- var $me = $(target);
- $me.textbox('textbox').focus(function () {
- if (!$me.data().isWidgetOpen) {
- var v = $me.textbox('getValue');
- $me.data().widgetValue = v;
- if ($.trim(v).length > 0) {
- console.log('setWidgetValue-notNull', v);
- } else {
- console.log('setWidgetValue-null', v);
- }
- }
- });
- $me.textbox('textbox').blur(function () {
- if (!$me.data().isWidgetOpen) {
- $me.data().widgetTmpValue = $me.textbox('getValue');
- console.log('setWidgetTmpValue', $me.data().widgetTmpValue);
- if ($me.data().widgetValue === $me.data().widgetTmpValue) {
- //值没有被修改
- return;
- }
- //值被改了,需要触发弹出
- //$me.searchbox('options').searcher.call($me[0]);
- //值被改了,需要被还原
- // $me.textbox('setValue', $me.data().widgetValue);
- } else {
- console.log('setWidgetTmpValue-igorn', $me.textbox('getValue'));
- }
- });
- }
- });
- $.extend(true, $.fn.searchbox.defaults, {
- inputEvents: $.extend({}, $.fn.textbox.defaults.inputEvents, {
- keydown: function (e) {
- if (e.keyCode === 13) {
- //需要强制触发一次 blur 事件
- e.preventDefault();
- var t = $(e.data.target);
- //先传值,避免出现搜索"回车搜索"的问题,也避免回车搜索无法清除上此搜索的结果
- t.searchbox("setValue", $(this).val());
- t.textbox('textbox').blur();
- var opts = t.searchbox("options");
- opts.searcher.call(e.data.target, t.searchbox("getValue"), t.searchbox("getName"));
- return false;
- }
- }
- })
- /*
- onBeforeValidate: function () {
- console.log('onBeforeValidate', $(this).val(), this, arguments);
- return false;
- },
- onValidate: function (valid) {
- //$(this).data().searchbox.widgetTmpValue = $(this).textbox('textbox').val();
- console.log('onValidate', $(this).val(), this, arguments);
- //var v = $(this).textbox('textbox').val();
- //$(this).searchbox('setWidgetTmpValue', v);
- return false;
- },
- onChange: function (newValue, oldValue) {
- //无论什么情况下,都直接返回编辑前的值
- var v = $(this).searchbox('getWidgetValue');
- if ($.type(v) === 'undefined') {
- v = '';
- }
- $(this).searchbox('initValue', v);
- console.log('onChange', $(this).val(), this, arguments);
- return false;
- }
- */
- //onChange: function (newValue, oldValue) {
- // var v1 = document.activeElement;
- // var v2 = $(this).textbox('textbox');
- // console.log(v1 === v2 ? 'onChange-F-yes' : 'onChange-F-no');
- //}
- });
- })(jQuery);
|