EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: ftmh on August 18, 2014, 01:31:41 AM



Title: Formatter foe TEXTBOX
Post by: ftmh on August 18, 2014, 01:31:41 AM
HI...
i want to have a formatter for the textbox , like datagird. how can ??

thank you  :)


Title: Re: Formatter foe TEXTBOX
Post by: stworthy on August 18, 2014, 03:13:57 AM
Try the code below:
Code:
(function($){
    function formatValue(target){
        var t = $(target);
        var opts = t.textbox('options');
        var v = t.textbox('getValue');
        if (opts.formatter && v){
            var v = opts.formatter.call(target, v);
            t.textbox('setText', v);
        }
    }
    var focusHandler = $.fn.textbox.defaults.inputEvents.focus;
    $.extend($.fn.textbox.defaults.inputEvents, {
        focus: function(e){
            if (focusHandler){focusHandler(e);}
            var t = $(e.data.target);
            var v = t.textbox('getValue');
            if (v){t.textbox('setText', v);}
        }
    });
    var initValue = $.fn.textbox.methods.initValue;
    $.fn.textbox.methods.initValue = function(jq, value){
        initValue.call($.fn.textbox.methods, jq, value);
        return jq.each(function(){
            var opts = $(this).textbox('options');
            formatValue(this);
            opts.value = value;
        });
    }
})(jQuery);

Usage example:
Code:
$('#t1').textbox({
formatter:function(value){
return value;
}
})


Title: Re: Formatter foe TEXTBOX
Post by: Stefan B. on January 09, 2015, 07:48:24 AM
Hi. This example is not working anymore! The error is:
Code:
TypeError: $(...).textbox(...) is undefined
$(_4ea).textbox("setValue",_4eb).textbox("setText",text);

But why this is not in easyui core?
We must have also an formatter for the Text in the textbox!

In exsample we would have an Link text in the easyui textbox! (text as hyperlink)
Is that possible?


Title: Re: Formatter foe TEXTBOX
Post by: stworthy on January 09, 2015, 08:20:55 AM
Please try this example http://jsfiddle.net/zsbpzqsj/.


Title: Re: Formatter foe TEXTBOX
Post by: fengguangyin on June 23, 2015, 06:29:25 AM
Hi,the example in http://jsfiddle.net/zsbpzqsj/ is not working too,the error:
Code:
TypeError: $(...).combo(...) is undefined

$(this).combo("initValue",_a45).combo("setText",_a45);

jquery.....min.js (第 13629 行)

My example has a datagrid.


Title: Re: Formatter foe TEXTBOX
Post by: stworthy on June 23, 2015, 08:52:41 AM
Please try this updated example http://jsfiddle.net/zsbpzqsj/6/.


Title: Re: Formatter foe TEXTBOX
Post by: fengguangyin on June 23, 2015, 09:27:53 AM
Hi,the example in  http://jsfiddle.net/zsbpzqsj/6/ has an other error :
Code:
TypeError: date.getHours is not a function
var tt=[_577(date.getHours()),_577(date.getMinutes())];
jquery.....min.js (第 7906 行,第 13 列)


Title: Re: Formatter foe TEXTBOX
Post by: jarry on June 23, 2015, 03:12:49 PM
That example has not getHours function. Please check your code carefully.


Title: Re: Formatter foe TEXTBOX
Post by: fengguangyin on June 23, 2015, 06:17:35 PM
I copy the code from the example in  http://jsfiddle.net/zsbpzqsj/6/ to my example. My example has some plugins, such as datetimebox,textbox,combobox,combogrid,datagrid. It cause the error as I posted above. But it has no error when I remove the code.

I find the error caused by the datetimebox, I change the code
function formatValue(target){
        var t = $(target);
        var opts = t.textbox('options');
        var v = t.textbox('getValue');
        if (opts.formatter && v){
           if(!$(target).hasClass('timespinner-f')){
               var v = opts.formatter.call(target, v);
               t.textbox('setText', v);
           }
        }
    }
That has no error,Is that right?