Jump to content

Preventing UniLabel Text Selection Highlighting


mos

Recommended Posts

I am trying to prevent text selection highlighting of a TUniLabel which is being dynamically created in code.

 

In the UniServerModule.CustomCSS I have the following:

.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Safari */
     -khtml-user-select: none; /* Konqueror HTML */
       -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; /* Non-prefixed version, currently
                                  supported by Chrome and Opera */
}

And In code I create the label and try to set the UniEvents beforeInit:

  FLbl := TUniLabel.Create(Self);
  FLbl.Parent := Self;
  FLbl.Font.Size := 20;
  FLbl.Left := 10;
  FLbl.Text := 'Hello There';
  FLbl.ClientEvents.UniEvents.Text := 'beforeInit=function beforeInit(sender, config)'#13#10'{'#13#10'  config.cls=' +
      '"noselect";'#13#10'}'

However the above does not work and I can still highlight the label text.

 

I know the CSS does work if I put a TUniLabel on a form and in the object inspector set the beforeInit.

 

What do I need to do to get the above code to work when the label is dynamically created?

Link to comment
Share on other sites

Hi,

 

For example:

 

1. CustomCSS:

*.unselectable {
   -moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   -ms-user-select: none;
   user-select: none;
}

2.

  FLbl := TUniLabel.Create(Self);
  FLbl.Parent := Self;
  FLbl.Font.Size := 20;
  FLbl.Left := 10;
  FLbl.Text := 'Hello There';
  FLbl.JSInterface.JSCall('addCls', ['unselectable']); //<---------

Best regards,

Link to comment
Share on other sites

  • 2 years later...
  • 2 years later...
25 minutes ago, rgreat said:

But is not there a way to set unelectable to all labels, globally?

Done myself:

.x-abs-layout-item, label {
  -moz-user-select: -moz-none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}


 

Link to comment
Share on other sites

25 minutes ago, rgreat said:

Is there a way to make "loading.." frame of ScreenMask unelectable too?

And again, myself:

.x-mask-msg {
  -moz-user-select: -moz-none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}


 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...