Blogs Blogs

Java Script on CCF Extension

Platform: Sales and Service | 3 Comments 05.04.2009   Sales & Service, CME User_comment
Categories: Development

All,

Can You Please explain or post samples on executing a java script from a CCF extension?

My requirement is to set focus on Telephone Number widget, Once the user finishes typing in all 3 digits on Telephone Area Code Widget.

RuntimeFormWidgetInterface does not seem to support setfocus method.

Thanks,
Kiruba

05.05.2009   Jason Ihaia Oe-admin

Hi there,

I think this is an interesting example of using javascript in Epiphany for client-side events. Generally speaking you see very little examples of this and hence why it is used less frequently than it could or should be.

While I’ve not tried this (yet), I have some thoughts that I’ll put out there before I attempt to try and validate.

I won’t go into the detail, as there is a reasonable explanation of some of the details of CCFs and Client-Side (CS) extensions and there relationship to Javascript and client-side events.
That being said, I don’t believe this should be overly difficult to overcome.

What I believe you are going to want to do is create a CCF extensiont that can respond to the onChange event for the area code field.

In the body of the extension, you are going to want to return the javascript that sets the focus.

Under normal circumstances, the Javascript for setting focus might look like this;

function setfocus(){
    document.forms[0].field.focus()
}

So at this stage, you will need to know the name of the field for the telephone number that you wish to set focus on the form. The documentation is quite cryptic when it comes to this so your best bet is to leverage a tool like HTTPWatch or another browser based interrogation tool to see what the name of the widget is.

From within your extension, you would simply return the javascript so that the framework executes it on the client-side.


public class MySetFocus extends JSCommandExtensionBase {
  protected int execute(RuntimeFormInterface form, RuntimeFormWidgetInterface formWidget, HashMap params) throws EpiException {
    String jsCode = "function setFocus(){document.forms[0].field.focus()";
    setResult("jsCode", jsCode);
    setStatus(STATUS_SUCCESS);
    return RET_CONTINUE;
  }
}

Please note that this is untested – for illustration purposes only. Not to mention you would probably consider how to make this generic to be used in other situations.

If you’ve not tried this approach I suggest you give it a go. If so, can you share your results. In the meantime, I’ll give this a try myself and report back my findings.

05.05.2009   Jason Ihaia Oe-admin

Just another quick thing to look at is one of the out-of-box extensions called – GetTemplateAndResolveFromDropDown.java.

If you cruise towards the bottom you will see where the javascript is built in the StringBuffer and output through the method setResult. This will give you an idea on how you get the widget by name.

05.07.2009   Sales & Service, CME User_comment

Thanks for your help. I am still not successful in achieving this.
CCF Extension gets fired.
But java script is not getting executed (even a simple alert or setvalue is not working).
Still working on this.

I was able to get it to work, by input from another Epiphany user.

An OOB Example Extension is: com.epiphany.common.shared.extension.ui.ClientClearWidgetValue

Extract from Epiphany User "Patrik"’s Note:

Create an extension that extends ClientJSExtensionBase with the following method
public class MyJSExtension extends ClientJSExtensionBase {
protected int execute(ClientEventProperties props) throws EpiException {
String data = (String)getParameterString(“data”);
Object[] args = {data};
super.setup(props, args);
return RET_CONTINUE;
}
}

Add your extension in this file /shared/webroot/app/js/extensions.js

function my_js_extension_package_MyJSExtension(slotId, formNumber, formWidgetName, objectId, appUrlKey, arg0){
Your javascript code
}

If you wish to comment on this post, please register or login.