Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
Hi All,
In FormShow I put some text into the a IWEdit control and then call iwedit1.setfocus. The text is shown, but the caret is positioned before the leftmost character.
In Tedit I would use Selstart to position the caret at the end of the text, but selstart is not a property / method of iwedit.
Do anyone have a suggestion as to how it can be done ?
Regards
Soren
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
You need to use one of the forms methods (without looking, AddScript, or something akin to that, there are examples in our demos) to add JS that will run after the page inits so set SelText via client side Javascript.
Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
Thanks Kudzu,
I'll check it out.
Regards
Soren
Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
Hi Kudzu,
Sorry but I have not managed to find the addscript demo (or demo with addscript in it) you mentioned.
In the ScrollMeno demo there is an example of how to use javascript to position the line top or bottom in scroll area, but I can't really see how make that work for Seltext and Selstart.
Was it the AddJavaScript function you meant ?
Regards
Soren
Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
Hi Alexandre,
Thank you very much for the code.
I'll try it out and let you know, but as you said, it should probably do the trick.
Regards
Soren
Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
09-10-2019, 05:03 AM
(This post was last modified: 09-10-2019, 06:31 AM by SorenJensen.)
Hi Alexandre,
I have now (finally) had time to test it, and I can confirm it works. The caret is placed after the text in the edit.
If I want the text to be selected I suppose I could use the same technique, but with other (or more) commands. Can you give me some hint as how to do ? EDIT: Found an answer: Use This.Select() in the ScriptEvents.OnFocus for the edit field.
Regards
Soren
Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
Hi Alexandre,
Since you showed me how to put JS into the code in the Forms create event to place the caret after the text in an edit control at the time it received focus, I have started to use the forms Javascript property to enter JC code. The lastest additions is the text for keypress F10 and ESC on formlevel.
But I am also using the ScriptEvents on component level. Mostly to make sure text in an component is "selected" when it receives focus, and lately also to convert text to Uppercase characters.
And that makes me think I could use the ScriptEvents for the IwEdit fields for the Caret positioning, either in the OnEnter event or the OnFocus event, instead of the way I do it now (as your example shows).
If it is possible to use ScriptEvents for that, how would you propose I do it ?
Regards
Soren
Posts: 185
Threads: 55
Joined: Jul 2019
Reputation:
2
Location: Luxembourg
Hi all,
This question is no longer relevant for me. I have found a solution:
In the IWEdit's Scriptevent, in OnFocus, I put the following:
var val = this.value;
this.value = "";
this.value = val;
That is working just as well as the JS injection in the FormCreate event proposed by Alexandre previously.
Thanks to Alexandre for the help. Your proposal worked fine and in fact pushed me in the right direction.
Regards
Soren
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
Thanks for the follow up and letting users know about your solution.