How can I access servoy methods from a html?

Forum to discuss the new web client version of Servoy.

How can I access servoy methods from a html?

Postby bodnarescu.diana » Tue Mar 07, 2023 5:08 pm

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:
Code: Select all
<html><a href="javascript:globals.myMethod()">ClickMe</a></html>


I have set these properties onLoad but it does not make a difference:
Code: Select all
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
Last edited by bodnarescu.diana on Tue Mar 07, 2023 7:51 pm, edited 1 time in total.
Diana Bodnarescu
Servoy Valued Professional
Freelance Servoy Developer
bodnarescu.diana
 
Posts: 25
Joined: Tue Mar 29, 2016 10:43 am

Re: How can I access servoy methods from a html?

Postby patrick » Tue Mar 07, 2023 5:30 pm

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

Code: Select all
<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?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: How can I access servoy methods from a html?

Postby bodnarescu.diana » Tue Mar 07, 2023 7:50 pm

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:
Code: Select all
..<input  onfocusout="javascript:globals.myMethod()">...



Diana
Diana Bodnarescu
Servoy Valued Professional
Freelance Servoy Developer
bodnarescu.diana
 
Posts: 25
Joined: Tue Mar 29, 2016 10:43 am

Re: How can I access servoy methods from a html?

Postby mboegem » Wed Mar 08, 2023 11:35 am

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.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: How can I access servoy methods from a html?

Postby bodnarescu.diana » Wed Mar 08, 2023 5:31 pm

It is clear now, thank you, Marc :)

I found a way to use this dataTarget so I can interact with my html the way I want.

Thanks Marc and Patrick,
Diana
Diana Bodnarescu
Servoy Valued Professional
Freelance Servoy Developer
bodnarescu.diana
 
Posts: 25
Joined: Tue Mar 29, 2016 10:43 am

Re: How can I access servoy methods from a html?

Postby swingman » Fri Mar 10, 2023 12:31 pm

Does this apply only to labels or can this technique also be used with other components like the Data Grid?
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1472
Joined: Wed Oct 01, 2003 10:20 am
Location: London


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 8 guests

cron