set focus at end of text in inputbox after ajax refresh

set focus at end of text in inputbox after ajax refresh

  

Hi All,

whenever we do ajax refresh on the inputbox cursor moves to the beginning of the text. If i want to keep the position of it or move it to the last. Is there any inbult way to do it.

Regards,

Manish Jawla

Manish Jawla wrote:

Hi All,

whenever we do ajax refresh on the inputbox cursor moves to the beginning of the text. If i want to keep the position of it or move it to the last. Is there any inbult way to do it.

Regards,

Manish Jawla


Hi Manish

You can use this javascript associated with your input:

"$('" + YourInput.Id + "').focus(function(){
  var that = this;
  setTimeout(function(){ that.selectionStart = that.selectionEnd = 10000; }, 0);
});"

Hope this helps.
Cheers, 

Eduardo Jauch

hi Eduardo Jauch,

Thank you so much for the quick response but when i tried the above javascript code in my personal environment it works fine but when i applied the same in my company application its not working :(. May be some conflict issue but i have already applied the no.conflict(); also but still not working.

Regards,

manish jawla

Hello Manish,

When you try it with company's application, if you inspect the app in browser and look to the console messages, their is anything? Errors?

Can be a conflict with other JavaScript in the page.

Cheers

Eduardo Jauch

Hi Eduardo Jauch ,

XML5632: only one root element is allowed.

This error message is appering while inspect element but same error is also coming in my personal environment and its working fine. I am using internet explorer 11 for the info.

cheers

Regards,

manish jawla 

Hello Manish,

This error is related to edge and probably is the same thing with IE. See here. It has no impact in the application, it seems.

The reason to the JavaScript to work in your personal, but not in your other application, if you are using the same browser version and the server version is the same, is probably related to other script in the page. 

Do you have any mask or any other widget associated with the input?

Cheers, 

Eduardo Jauch

Hey Eduardo Jauch,

You are right but there are lots of javascript code on that page and i cannot remove it. I have to found some work around for that. Thanks for the help.

Regards,

Manish Jawla

Hi Manish,

To set the focus you can add autofocus as an extended property, with value "autofocus", in the input you want to have the focus.

I'm not sure if it will place the cursor caret at the beginning or end, by I think the first.
Than, to put in the end, I think only using JavaScript.

In this case, you will have to study the page to see if a change in the "moment" the JavaScript is executed solves the problem, like put it in a web block or expression, in the end of the page.

Cheers,
Eduardo Jauch

Hi Jauch,

How to set the focus using "autofocus" extend property on Popup Notify Server action

My Use Case:

After selecting address, i want to set the focus to Billing Street text box

Because User needs to enter door number, It wont come with the search result.



Thank you,

Sekar

Hello Sekar,

In your case, you can't use "autofocus", because this attribute action happens only when the page is loaded.
This is not the case when you close the pop up.

You will have to make a "Notify" in the popup and in the OnNotify action of the page, set the focus using a method like the one I showed before, with JavaScript, using a RunJavaScript server action. I think in this case the RichWidget InputFocus would not work.

Cheers,
Eduardo Jauch

Hi Jauch,

RunJavascript Server action means the Script Action right.

Do i need to call this action before or after ajax refresh?



Thank you,

Sekar


Hi,

No. RunJavaScript action is part of the HTTPRequestHandler api:

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/HTTPRequestHandler_API#RunJavaScript

Cheers,
Eduardo Jauch

Thanks Jauch,

Sometime back i have unchecked all the server actions in HTTPRequestHandler API

and today I searched its was missing so got confused.

Thanks a lot Jauch.

You're welcome :)