Hello,
Is there a way I can access my servoy methods from a html?
For example I am displaying this in a label that has showAs: trusted_html:
<html><a href="javascript:globals.myMethod()">ClickMe</a></html>
I have set these properties onLoad but it does not make a difference:
elements.html_label.putClientProperty(APP_UI_PROPERTY.ALLOW_JAVASCRIPT_LINK_INPUT, true);
elements.html_label.putClientProperty(APP_UI_PROPERTY.TRUST_DATA_AS_HTML, true);
It works if i set this property to false: servoy.ngclient.setContentSecurityPolicyHeader, but this is not desired.
Thank you,
Diana
I suppose that you want fire a method from your html, because you only want to allow a click on some part of the (html) content, not the whole label, right? Or because you want to have two clicks from your html that do different things?
The nice way of doing this is to use the data-target attribute on the part of your html where you want the click to be dealt with. Something like this for example
<div data-target="a">some content</div><div data-target="b">some other content</div>
Note that the onAction handler of a label receives a dataTarget parameter. What that does is: whenever the user clicks on your content, the client will find the closest data target attribute and return that to your method. So in your onAction method you can look at that value and determine where the user clicked.
Would that solve your problem?
Thank you for your answer, Patrick, that works for a click action which indeed was in my example.
Given you suggested this alternative, this means I can no longer access servoy methods from a html?
Like in this piece:
..<input onfocusout="javascript:globals.myMethod()">...
Diana
Hi Diana,
Servoy methods are not exposed in the (Ti)NG client, this means that referencing a Servoy method from html will never work.
Therefor the dataTarget way as described by Patrick is the way to do this.
dataTarget does not only work for labels, but also for example for dataLabels, tabs, custom list component, foundset list component and checkboxes (I believe even buttons)
Also I noticed that your example contained html-tags, as the label component is already an element within html, this is no longer necessary
Hope this will clarify things.
It is clear now, thank you, Marc ![Smile :)]()
I found a way to use this dataTarget so I can interact with my html the way I want.
Thanks Marc and Patrick,
Diana
Does this apply only to labels or can this technique also be used with other components like the Data Grid?