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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...