862
Views
4
Comments
Solved
SetFocus
Question

I need set focus from one input, on "Onblur" event to another input, i've tried create a javascrip Function on a form:

function setFocusToTextBox(x){
    document.getElementById(x).focus();
}

and in the input, onblur event, i put like this:

"setFocusToTextBox(" + AddDebito.Id + ")"

But all this didn't work, and i dont have a clue that i'm supposed to do now

Rank: #70618
Solution

Thanks, but i discovered a way to do this. In the form, on javascrip, i put this

function SetFocus(widgetId)
{
  $(function($){
    var widget = document.getElementById(widgetId);
    if (widget == null)
    {
        try {
            window.OsHandleException(new Error("Invalid use of RichWidgets\\Input_SetFocus: Please specify the runtime Id property of an Input or Input Password widget."), outsystems.osErrorCodes.SystemJavascriptError, 'Input_SetFocus');
        } catch(e) {}
        return;
    }

    widget.focus();
    widget = null;
  });
}


And on "Onblur" event, i set the widget id that i want to go. I copied this code from input_setfocus on Richwidgets and changed some little things :)

mvp_badge
MVP
Rank: #2

Debug! :) Joking aside, check whether the setFocusToTextBox is actually called by adding a Console.Log in there (it would be wise to also include the value of "x") and checking the console via your browser's devtools. Also check for any JavaScript errors in the console.

Rank: #70618
Solution

Thanks, but i discovered a way to do this. In the form, on javascrip, i put this

function SetFocus(widgetId)
{
  $(function($){
    var widget = document.getElementById(widgetId);
    if (widget == null)
    {
        try {
            window.OsHandleException(new Error("Invalid use of RichWidgets\\Input_SetFocus: Please specify the runtime Id property of an Input or Input Password widget."), outsystems.osErrorCodes.SystemJavascriptError, 'Input_SetFocus');
        } catch(e) {}
        return;
    }

    widget.focus();
    widget = null;
  });
}


And on "Onblur" event, i set the widget id that i want to go. I copied this code from input_setfocus on Richwidgets and changed some little things :)

mvp_badge
MVP
Rank: #47

Hi Deivd,

This issue could be related to the place you are defining your javascript function.  This code should be placed on the javascript property from the Screen where you put your form. Inside the onblur event you can use it directly.


Try to use de chrome dev tools to open console and try to test this call directly there. You will have more specific error message there to help you to fix it. When you are using custom javascript directly on your code, the error messages are not so clear at most of the time.


Best Regards

Fabio Fantato 

Rank: #43851

Hi Deivd,

OutSystemsUI provide SetFocus client action u can follow steps :

  1. Take dependencies from OutSystemsUI =>SetFocus

  2. Call SetFocus in Onblur .
  3. Set widgetID