EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: cannon on February 08, 2016, 12:23:17 AM



Title: text focus event won't work
Post by: cannon on February 08, 2016, 12:23:17 AM
The textbox focus event does not work, the value of x is correct, but the component is not filled with the new value, any tips? Regards.

Code:
    $(document).ready(function () {
        $('#txtSchool').textbox('textbox').bind('keypress focus blur', function (e) {
            CallEvents($(this), e);})
    });

    function CallEvents(Sender, e) {           
        if (e.type == 'focus') {
            var rd = $(Sender).prop('readonly');
            var rd = false; //testing...
            if (!rd) {
                var q = String($(Sender).val());
                var x = q.replace(/\./g, "a");   //replacing dot by a
                //$.messager.alert('School', 'focus ' + x, 'info');
                $(Sender).val(x);   //does not fill the required field with the x content
                return;
            }
        }
        else if (e.type == 'keypress') {
            //$.messager.alert('School', 'keypress ', 'info');
        }
        else if (e.type == 'blur') {
            //$.messager.alert('School', 'blur', 'info');
        }
    };


Title: Re: text focus event won't work
Post by: cannon on February 08, 2016, 04:45:39 AM
ther's a bug... in my brain, or really the event on focus don't work

Code:
$('#txt').textbox('textbox').on('focus', function () {
       $(this).val("00000");         //don't set
});

or

$('#txt').textbox('textbox').bind('focus', function () {
       $(this).val("00000");         //don't set
});

or

$('#txt').textbox('textbox').bind('focusin', function () {
       $(this).val("00000");         //don't set
});

curiously the keypress event works!


Title: Re: text focus event won't work
Post by: jarry on February 08, 2016, 05:47:21 AM
Please refer to this example http://jsfiddle.net/vxh8ydfy/1/. It works fine.


Title: Re: text focus event won't work
Post by: cannon on February 08, 2016, 06:49:23 AM
Thank you, Jarry.

In my aspx page is not working and the code is the same, I will study more.