Jump to content

TUniEdit SelStart


droider

Recommended Posts

  • 3 weeks later...

Can you try this simple implementation ?!:

 

1. MainForm -> Script:

function selectSE(id, start, end) {
    var input = document.getElementById(id);
    if ('selectionStart' in input) {
        input.selectionStart = start;
        input.selectionEnd = end;
        input.focus();
    } else { // Internet Explorer before version 9
        var inputRange = input.createTextRange();
        inputRange.moveStart("character", 1);
        inputRange.collapse();
        inputRange.moveEnd("character", 1);
        inputRange.select();
    }
}

2. How to use, for example:

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  UniSession.AddJS('selectSE('+UniEdit1.JSName+'.inputEl.id, 0, 2)');
end;

Best regards,

Link to comment
Share on other sites

I tried the simple but unfortunately "selectSE is not defined" when calling it.. I put it in my Main.Script property as you told be, but it does not seems to recognize the fonction; does I have to enable something more ?

 

Best regards,

Link to comment
Share on other sites

Hi,

 

I don't know why, on a minimalist testCase project, I have no issue and highlighting is working properly, but on my own project, function selectSE is never recognize .. any idea ; workaround ?  :(

 

Ok, try this approach:

 

1. MainForm -> Script:

Ext.form.field.Text.prototype._selectSE = function(start, end) {
    var input = document.getElementById(this.inputEl.id);
    if ('selectionStart' in input) {
        input.selectionStart = start;
        input.selectionEnd = end;
        input.focus();
    } else { // Internet Explorer before version 9
        var inputRange = input.createTextRange();
        inputRange.moveStart("character", 1);
        inputRange.collapse();
        inputRange.moveEnd("character", 1);
        inputRange.select();
    }
}

2. Use like this:

UniEdit1.JSInterface.JSCall('_selectSE', [0, 2]);

Best regards,

Link to comment
Share on other sites

  • 2 weeks later...

Hello Lion ! (:

 

Sorry I didn't have time until now to handle this problematic! (;

 

This solution is better because I don't have the same issue: _selectSE is always recognize, but my text is not selected neither highlighted ! :(

This solution still work properly on my minimalist test project.

Any idea or workaround why text is not selected ?  :wacko:

 

Best regards,

Link to comment
Share on other sites

  • 2 weeks later...

I did manage to select and highlight my text: I was launching highlight after a onButtonClick event :

begin

  uniEdit1.Text := 'This is my TEXT to be selected';

  uniEdit1.JSInterface.JSCall('_selectSE', [12, 16]);

end;

 

Apparently the first line was affecting the JS call because nothing was higlighted, so I did the same thing but directly in JS:

 

Ext.form.field.Text.prototype._selectSE = function(text){
   var input = document.getElementById(this.inputEl.id);
   input.value = text;
   start = text.search("VALEUR");
   end = start + 6;
   if ('selectionStart' in input) {
      input.selectionStart = start;
      input.selectionEnd = end;
      input.focus();
      input.focus();
   } else {
      var inputRange = input.createTextRange();
      inputRange.moveStart("character", 1);
      inputRange.collapse();
      inputRange.moveEnd("character", 1);
      inputRange.select();
   }
}
Calling the JS method as you told me :
EFilter.JSInterface.JSCall('_selectSE', ['Ceci est la VALEUR à souligner']);
 
Best regards,
 
Link to comment
Share on other sites

  • 1 year later...
6 minutes ago, bahry said:

I just would like to mark (select) a part of that text

 

 

I use the following in UniEdit 

ClientEvents --> UniEvents 

function beforeInit(sender, config)
{
  config.selectOnFocus=true;
}

and it's working as expected.

 

Regards

 

 

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...