I have a model component (dialog) which pops up when a button is clicked. There's a table on this modal component with a column containing a tick box. I'm trying to toggle the value of the tick boxes on each row by clicking the title of the column. I've done this by adding some jquery to the <th> of that column which calls a client accessible function to iterate through the rows and tick / un-tick the boxes.
The problem is, although I have added the javascript containing the server-side function to the client callable functions of the component, it tells me that the function is not accessible when looking in the runtime log. In order for this to work I seem to have to add the client callable functions script to the form that contains the component (host form). This then means I can't reference the controls within the scope of the component, I have to use full control / field names and it then becomes bespoke to that form.
Am I missing something? Has anybody else had this issue?
Thanks
Components & Calling Client Accessible Functions
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 68
- Joined: Wed Aug 15, 2012 1:22 pm
Components & Calling Client Accessible Functions
Last edited by geadon on Fri Jul 13, 2018 7:38 pm, edited 1 time in total.
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Components & Calling Client Accessiblee Functions
Where do you activate the jQuery from - a ready event somewhere? If you do this from a control inside the component the system should be able to identify this and handle it. But if you do this from a form level control, the system will assume that your event is at form level as well.
You can check whether the component context is being set correctly using a browser debug tool - if you look at the network URLs called, then check the content of the jQueryEventRegistration servlet. Here you will see all the jQuery events you have configured. If the system thinks any given event is for a component you will see a line like this:
com.ebasetech.clientapi.componentPrefix=xxxxx
You can check whether the component context is being set correctly using a browser debug tool - if you look at the network URLs called, then check the content of the jQueryEventRegistration servlet. Here you will see all the jQuery events you have configured. If the system thinks any given event is for a component you will see a line like this:
com.ebasetech.clientapi.componentPrefix=xxxxx
0 x
-
- Ebase User
- Posts: 68
- Joined: Wed Aug 15, 2012 1:22 pm
Re: Components & Calling Client Accessiblee Functions
Thanks for the great advice Jon.
I'm activating the jquery from the ready event of the column in question (in the component).
The content of the jQueryEventRegistration servlet appears to be correct:
Any other suggestions?
I'm activating the jquery from the ready event of the column in question (in the component).
The content of the jQueryEventRegistration servlet appears to be correct:
Code: Select all
$(document).ready(function() { try
{
com.ebasetech.clientapi.componentPrefix = "a_dlg_Allocate__";
// user code
$('th.avlHeading').click(function() {
$eb.executeFunction('toggleAVL');
});
// end of user code
}
finally
{
com.ebasetech.clientapi.componentPrefix = null;}
});
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Components & Calling Client Accessible Functions
Ah, I see. The component prefix is being applied to the ready() event code but it won't be transferred to the click() event code. To get this to work you would need to set the component prefix explicitly inside your click function, so change your code to something like this:
The problem with this is that you then have the component prefix hard-coded which is less than ideal.
Code: Select all
$('th.avlHeading').click(function() {
com.ebasetech.clientapi.componentPrefix = "a_dlg_Allocate__";
try {
$eb.executeFunction('toggleAVL');
}
finally {
com.ebasetech.clientapi.componentPrefix = null;
}
});
0 x
-
- Ebase User
- Posts: 68
- Joined: Wed Aug 15, 2012 1:22 pm
Re: Components & Calling Client Accessible Functions
Thanks for confirming this Jon. Wasn't sure if I was doing something wrong or not. Agree that it does defeat the object of using a component if I have to hard code the prefix, so I will explore other options.
Many thanks
Many thanks
0 x
-
- Ebase User
- Posts: 82
- Joined: Fri Jan 15, 2016 2:34 pm
Re: Components & Calling Client Accessible Functions
I encountered similar issues recently with calling client-accessible functions from a component. Like you, I had to go the route of including the client function file in the form in addition to the component. According to the documentation, it seems like client-callable functions inside components should work the way geadon and I expected it to:
Jon, is this a bug or is this the way it's supposed to work? As you noted, having to hardcode the component prefix somewhere largely defeats the purpose of using client-callable functions inside a component.
Source: https://vault.verj.io/ebase/doc/Compone ... c413503108When performing an executeFunction command the Client API will look for the Client Callable Function in:
1. The target form, where the function will use form-level mappings. Thus Client Callable Functions in the form override ones inherited from a component.
2. The inserted component, as long as an Event Handler from the component triggered the Client API call (either directly or indirectly) and that Event Handler hasn’t been overridden. In this case the function will use component-level mappings.
Jon, is this a bug or is this the way it's supposed to work? As you noted, having to hardcode the component prefix somewhere largely defeats the purpose of using client-callable functions inside a component.
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Components & Calling Client Accessible Functions
The reality is that there are some circumstances in which it doesn't work - like the one listed here. I guess you could say that it's a bug, as it's not the behaviour that you expect, but it's not one that's likely to be fixed. The technical issue is that it's hard for the Ebase system to work out the context on the client (i.e. in a component or not). It tries to solve this by setting a component context variable around the execution of jQuery events - see above, but this doesn't work where one jQuery event is used to trigger another one on a different HTML element.
0 x
-
- Ebase User
- Posts: 82
- Joined: Fri Jan 15, 2016 2:34 pm
Re: Components & Calling Client Accessible Functions
I encountered this problem again today of wanting to call a client function from inside a component, with component-level mappings. It looks like I've managed to find a workaround to the issue of the componentPrefix not being set.
Below is the code I'm now using on a component's field control's ready jQuery event. All that's needed to work around the issue is to store the com.ebasetech.clientapi.componentPrefix value when it's correct (ie at the very start of the handling) into a local variable. Then, when an event within your handler is handled, use that local variable to re-assign the correct componentPrefix.
Below is the code I'm now using on a component's field control's ready jQuery event. All that's needed to work around the issue is to store the com.ebasetech.clientapi.componentPrefix value when it's correct (ie at the very start of the handling) into a local variable. Then, when an event within your handler is handled, use that local variable to re-assign the correct componentPrefix.
Code: Select all
console.log('onReady: '+ com.ebasetech.clientapi.componentPrefix); // (correct prefix)
var _prefix = com.ebasetech.clientapi.componentPrefix;
$(".med").autocomplete({
source: function( request, response ) {
console.log('before assignment: '+ com.ebasetech.clientapi.componentPrefix); // null
com.ebasetech.clientapi.componentPrefix = _prefix;
console.log('after assignment: '+ com.ebasetech.clientapi.componentPrefix); // (correct prefix) (!)
{...}
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
-
- Ebase User
- Posts: 68
- Joined: Wed Aug 15, 2012 1:22 pm
Re: Components & Calling Client Accessible Functions
Thanks for sharing Eric. Would be nice if Ebase fixed this so no workaround is needed
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Components & Calling Client Accessible Functions
For info, in V5.5 we have expanded the client API to make it easier to work with components: you can obtain the component prefix on the client and pass this as a parameter on $eb.executeFunction() calls e.g.
Code: Select all
var pfx = $eb.getComponentPrefix();
var xx = $eb.executeFunction("func1", null, false, false, null, pfx);
0 x
-
- Ebase User
- Posts: 82
- Joined: Fri Jan 15, 2016 2:34 pm
Who is online
Users browsing this forum: No registered users and 9 guests