CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

IWCGJQHTMLEditor1 Set Focus

by jandekkers » 16 Jun 2014 23:30

With TMS' I would set the focus to the HTML Editor as follow (How do I do this with IWCGJQHTMLEditor ?)

>> Please note: I want to set the focus to the 1st line in the text, not at the bottom!

Code: Select all
 function fxSetJavaScriptFocus: string;
 var
   lJS  : TStringList;
 begin
   lJS := TStringList.Create;
   try
      lJS.Add('');
      lJS.Add('function setFocus()');
      lJS.Add('{');
      lJS.Add(' editor = TIWHTMLEDITMESSAGEgetIFrame(''TIWHTMLEDITMESSAGEeditorDiv'');');
      lJS.Add(' editor.focus();');
      lJS.Add('}');
      Result := lJS.Text;
   finally
      lJS.Free;
   end;
 end;

begin
  self.JavaScript.Text := fxSetJavaScriptFocus;
  AddToInitProc('window.onLoad=setFocus();');
end;
jandekkers
 
Posts: 74
Joined: 09 May 2014 23:05

by Alexander Bulei » 17 Jun 2014 10:17

Hi jandekkers,

In this case, the setFocus function needs to be more complex.
We will fix/implement it asap.

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by Alexander Bulei » 17 Jun 2014 15:06

Hello,

Fixed/Implemented in V2.1.0.3689.

Thanks.

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by jandekkers » 15 Jul 2014 18:51

I am revisiting this problem. Currently I am using CG version 2.2.1.2 and would like to set the focus to the 1st line of text displayed in the HTML Editor. You said this was possible but how ?

Jan
jandekkers
 
Posts: 74
Joined: 09 May 2014 23:05

by Alexander Bulei » 16 Jul 2014 09:05

Hi,

Please check this topic: viewtopic.php?f=3&t=1588

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by jandekkers » 16 Jul 2014 18:28

Thanks, for anyone interested I created this function In formcreate which works great:

Code: Select all
 
procedure TformPortalReplyCreate.IWAppFormCreate(Sender: TObject);

 function fxSetJavaScriptFocus: string;
 var
   lJS  : TStringList;
 begin

   lJS := TStringList.Create;
   try
      lJS.Add('');
      lJS.Add('function setCaretAtStartIframeBody(iframe)');
      lJS.Add('{');
      lJS.Add('  var doc = iframe.contentDocument,');
      lJS.Add('  win = iframe.contentWindow;');
      lJS.Add('  doc.body.focus();');
      lJS.Add('    if (win.getSelection && doc.createRange)');
      lJS.Add('   {');
      lJS.Add('        // IE >=9 and non-IE');
      lJS.Add('        var sel = win.getSelection();');
      lJS.Add('        var range = doc.createRange();');
      lJS.Add('        range.setStart(doc.body, 0);');
      lJS.Add('        range.collapse(true);');
      lJS.Add('        sel.removeAllRanges();');
      lJS.Add('        sel.addRange(range);');
      lJS.Add('    }');
      lJS.Add('    else if (doc.body.createTextRange)');
      lJS.Add('   {');
      lJS.Add('        // IE < 9');
      lJS.Add('        var textRange = doc.body.createTextRange();');
      lJS.Add('        textRange.moveToElementText(doc.body);');
      lJS.Add('        textRange.collapse(true);');
      lJS.Add('        textRange.select();');
      lJS.Add('    }');
      lJS.Add('}');
      lJS.Add('');
      lJS.Add('function setFocus()');
      lJS.Add('{');
      lJS.Add(Format('  var elrteObj = $("#%s").get(0).elrte;',[IWCGJQHTMLEditor1.JQHTMLName]));
      lJS.Add('  $(elrteObj.doc.body).scrollTop(0);');
      lJS.Add('  setCaretAtStartIframeBody(elrteObj.iframe);');
      lJS.Add('}');
      Result := lJS.Text;
   finally
      lJS.Free;
   end;
 end;

BEGIN
  self.JavaScript.Text := fxSetJavaScriptFocus;
  AddToInitProc('window.onLoad=setFocus();');
END;

jandekkers
 
Posts: 74
Joined: 09 May 2014 23:05

by Jorge Sousa » 18 Jul 2014 09:43

Hi Jan

Thank you for sharing this code.

if you want, we can go forward to a next level, putting this javascript in a file and be loaded by Intraweb.

This will have the advantage of cutting a little bit in the upstream size, as well as be able to control this part from outside, without the need of recompile.
Best Regards
CGDevTools Develop / Support Team
Home Page: http://www.cgdevtools.com
Jorge Sousa
 
Posts: 4261
Joined: 17 May 2012 09:58

by jandekkers » 21 Jul 2014 18:55

since I have it implemented and working there is no direct need on my part but if it can help other people, sure that's great.

Jan
jandekkers
 
Posts: 74
Joined: 09 May 2014 23:05

by Alexander Bulei » 22 Jul 2014 11:22

Hi jandekkers,

We have implemented the new method to do this ;)

Available since V2.2.1.12.

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal


Return to JQHTMLEditor

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.