Help in the Focus event, does not want to work

Asked

Viewed 429 times

1

The textbox Focus Event does not work, the x value is correct, but component does not change its value, any hint, please.

    $(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('SCObraNet', 'focus ' + x, 'info');
                $(Sender).val(x);   //não preenche o campo solicitado com o conteúdo x
                return;
            }
        }
        else if (e.type == 'keypress') {
            //$.messager.alert('SCObraNet', 'keypress ', 'info');
        }
        else if (e.type == 'blur') {
            //$.messager.alert('SCObraNet', 'blur', 'info');
        }
    };
</script>

I tested in other ways and nothing, for example

    $('#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
    });
  • You have characters inside the arguments here CallEvents($(this), e);})... mute to CallEvents(this, e)

1 answer

1

The function CallEvents takes two arguments. O this and the event. You’re passing "trash" to the role as ; and a ) the more. You don’t need to pass $(this) 'cause Callevents already does $(Sender), that will suffice:

CallEvents(this, e);

You could also change that Callevents function to :

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

function CallEvents(e) { 
    var Sender = $(this);           
    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('SCObraNet', 'focus ' + x, 'info');
            Sender.val(x);   //não preenche o campo solicitado com o conteúdo x
            return;
        }
    }
    else if (e.type == 'keypress') {
        //$.messager.alert('SCObraNet', 'keypress ', 'info');
    }
    else if (e.type == 'blur') {
        //$.messager.alert('SCObraNet', 'blur', 'info');
    }
};
  • Hello Sergio. As I am using easyui-textbox it is necessary to pass the function as argument yes, I did the test as you suggested and it did not work. But the biggest problem is that I can’t change the value in either Focus, focusin, focusout or Blur, none of these events succeed.

  • @Cannon777 because you use $('#txt').textbox('textbox')? this is a plugin .textbox()? you have a link to the plugin?

  • I am using the Easyui framework, follow the link: [link] (http://www.jeasyui.com/) very good by the way. I was able to solve it in other ways. Very grateful to you for commenting.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.