EasyUI Forum
May 08, 2024, 04:18:02 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Formatter foe TEXTBOX  (Read 17361 times)
ftmh
Newbie
*
Posts: 19


View Profile
« on: August 18, 2014, 01:31:41 AM »

HI...
i want to have a formatter for the textbox , like datagird. how can ??

thank you  Smiley
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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;
}
})
« Last Edit: June 23, 2015, 08:49:31 AM by stworthy » Logged
Stefan B.
Full Member
***
Posts: 152


Software Architekt


View Profile Email
« Reply #2 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?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: January 09, 2015, 08:20:55 AM »

Please try this example http://jsfiddle.net/zsbpzqsj/.
Logged
fengguangyin
Newbie
*
Posts: 5


View Profile Email
« Reply #4 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: June 23, 2015, 08:52:41 AM »

Please try this updated example http://jsfiddle.net/zsbpzqsj/6/.
Logged
fengguangyin
Newbie
*
Posts: 5


View Profile Email
« Reply #6 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 列)
« Last Edit: June 23, 2015, 09:50:11 AM by fengguangyin » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #7 on: June 23, 2015, 03:12:49 PM »

That example has not getHours function. Please check your code carefully.
Logged
fengguangyin
Newbie
*
Posts: 5


View Profile Email
« Reply #8 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?
« Last Edit: June 24, 2015, 03:55:43 AM by fengguangyin » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!