Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hello again,
Does anyone have experience with embedding the XUI form? I know little JS however the problem I am having is finding a reference to 'prefixes' (Application.event.target for example), also I am not sure what event's could be used (so for example onClick - does it even exist in XUI?).
One of the examples of what I am trying to do:
I would like to add textbox with a new id when the button with lablel 'Add Company Name' is clicked - I understand the logic, go to box object with id="coname", count textboxes, add new textbox with counter+1, however it is really hard to say what to use, for example 'Application.something' or 'Application.event.target.' or anything else (I am not sure how many 'prefixes' exist). Does anyone have a JS reference that they use while implementing embedded forms? or any examples of embedded forms?
<box id="coname">
<label label="COMPANY-NAME"/">
<textbox id="1">
<value></value>
</textbox>
<textbox id="2">
<value></value>
</textbox>
<button label="Add" company=" name"="></button>
<script type="application/x-javascript" ev:event="domactivate">
//var test = Application.document.getElementbyId('coname');
Application.alert('test');
</script>
</box>
Any help would be really appreciated, as always!
Thanks
Marcin
Hi Clay
Great reply, thanks for the information, very helpful!
Is there a reference where I can find information about the 'prefixes'?
Thanks
Marcin
In Reply to Clay Helberg:
Hi Marcin--
Where the "prefixes" are used in XUI is primarily to get the document
that forms the basis of the dialog, so you can modify it in the way you
describe. You can typically do this by using
Application.event.target.ownerDocument. From there, you can use
getElementById() to find the thing you're looking for, and the usual DOM
methods to modify the tree. For the example you describe, the code would
look something like this:
<window>
<box id="coname">
<label label="COMPANY-NAME"/">
<textbox id="t1">
<value></value>
</textbox>
<textbox id="t2">
<value></value>
</textbox>
</box>
<button label="Add" company=" name"=">
<script ev:event="domactivate" type="application/x-javascript">
// get the dialog document object
var dlgdoc = Application.event.target.ownerDocument;
// now get the target box
var box = dlgdoc.getElementById("coname");
// create a new textbox
var tb = dlgdoc.createElement("textbox");
// set the ID attribute
tb.setAttribute("id", "t" +
(box.getElementsByTagName("textbox").length + 1))
// create the child value element and add it
var val = dlgdoc.createElement("value");
tb.appendChild(val);
// finally, add the new textbox to the exiting box
box.appendChild(tb);
</script>
</button>
</window>
A couple of things to note:
1) The <script> element that we want to trigger when the button is
pressed needs to be inside the <button> element. (There are other ways
you can tie them together with the event attributes, but this is the
easiest way to do it.)
2) You probably want the <button> element to be outside the box, so
you can freely add new fields to the box without worrying about where
the button is.
3) The allowed events are described in the help center, under the
title "Event Types". For most things where you want to react to a click,
DOMActivate is the event you'll want to listen for. The mouse events
tend to be limited to the edit window, they are not very useful for XUI
dialogs.
Hope that helps. Happy XUI development!
--Clay
Clay Helberg
Senior Consultant
TerraXML
Hi Clay/All
Thanks a lot for the previous answers, really useful stuff.
I am stuck at a weird 'bug' - any clue what could be wrong? Code below.
Also, is there a way to find out what exception is JS throwing when it fails?
Thanks
Marcin
//this script is for the <window> element and the action is on WindowLoad
<script type="application/x-javascript" ev:event="WindowLoad">
var actdoc = Application.activeDocument;
//var xuidoc = Application.event.target.ownerDocument;
var myWindow = Application.event.target;
var xuidoc = myWindow.dialogView.document;
var parentElement = actdoc.getElementsByTagName('sample:parent').item(0);
var childrenElements = coreEnrichment.getElementsByTagName('sample:child');
//var childrenElementsLength = coreCompany.length;
//var childrenElementsLengthInt = parseInt(coreCompanyLength);
Application.alert(childrenElements.length); // THIS RETURNS 4
for (var i=0;i<childrenelements.length;i++)< p=">
//when I substitute 'childrenElements.length' with number 4 it does not break
//however if i use childrenElements.length which returns 4 in the alert box it just breaks the script
{
some code in here
}
</script>