Atozed Forums
IWEdit caret position - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: IWEdit caret position (/thread-1200.html)



IWEdit caret position - SorenJensen - 08-22-2019

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


RE: IWEdit caret position - kudzu - 08-22-2019

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.


RE: IWEdit caret position - SorenJensen - 08-23-2019

Thanks Kudzu,

I'll check it out.

Regards
Soren


RE: IWEdit caret position - SorenJensen - 08-24-2019

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


RE: IWEdit caret position - Alexandre Machado - 08-25-2019

in your Form's OnCreate event, write this:


Code:
var
  js: string;
begin
  js := 'var input = IW.$("IWEDIT1");' +
        'if (input) {' +
        '    input.focus();' + 
        '    var val = input.value;' +
        '    input.value = "";' +
        '    input.value = val;' +
        '}';
  Self.AddToInitProc(js);
end;


It will probably do the trick


RE: IWEdit caret position - SorenJensen - 08-27-2019

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


RE: IWEdit caret position - SorenJensen - 09-10-2019

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


IWEdit caret position, moew - SorenJensen - 09-23-2019

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


RE: IWEdit caret position - SorenJensen - 09-28-2019

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


RE: IWEdit caret position - kudzu - 09-28-2019

Thanks for the follow up and letting users know about your solution.