Home Forums General XMetaL Discussion can we create checkbox in xmetal Reply To: can we create checkbox in xmetal

Derek Read

Reply to: can we create checkbox in xmetal

With XFT:

One way to do this would be with an embedded XFT form created using the XMetaL Form Layout Tool included with XMetaL Developer. See the Customization Guide topics called “[url=http://na.justsystems.com/webhelp/en/xmetaldeveloper/cg/6.0/cg.html#Forms]Forms[/url]” and “[url=http://na.justsystems.com/webhelp/en/xmetaldeveloper/cg/6.0/cg.html#Create%20a%20form]Create a form[/url]”. One of the standard controls is a checkbox (in the layout tool it is actually called a “CheckButton”). It supports two-state and tri-state rendering (ie: on/off or on/grey/off). You will also want to read the Customization Guide topic “[url=http://na.justsystems.com/webhelp/en/xmetaldeveloper/cg/6.0/cg.html#Associate%20a%20form%20with%20a%20customization%20object]Associate a form with a customization object[/url]” (and note that when that topic says “object” they are referring to an XML element).

You will probably need to add script to the XFT to handle reading and writing the attribute values for the “CheckButton” into and out of the XML because the state of the control (“checked” or “unchecked”) probably does not immediately translate from a boolean true/false value to 1/0. I suspect you will need additional logic that would likely end up in the XFT events called “OnXftPutDocToForm” and “OnXFTPutFormToDoc”.

One thing to watch out for is to not allow a document to contain too many embedded XFT forms. Each XFT form instantiates its own separate WSH engine (JScript or VBScript or other depending on how you have set it up) so each “live” form (all embedded forms are “live”, modal forms are only “live” when visible) eats up CPU and memory resources. In general I would avoid having more than a dozen forms in one document. I'm specifically mentioning this because, depending on your document model, you might be tempted to allow a document to render 100 XFT forms containing checkboxes.

Without XFT:

One very simple thing to do would be to add script to an event like “On_Double_Click” inside which you would check to see if the current element is “myElement”. If it is you would then check the current value for @val. If it is 1 then you would change it to 0, if it is 0 you would change it to 1. Basically just toggle between two values, keeping in mind that the attribute might not be set at all:

if(Selection.ContainerName == "myElement") {
 if(Selection.ContainerAttribute("val") == "" || Selection.ContainerAttribute("val") == "0") {
   Selection.ContainerAttribute("val") = 1;
 else {
   Selection.ContainerAttribute("val") = 0;

There might be one more case to check for above. If your DTD sets this attribute as CDATA then someone or something might have (legally) set the value to something else (and XMetaL Author will not raise validation errors). You might check to see if the value was anything other than null/0/1 and force it to one of those. [Note: If you truly want just 0/1 to be allowed and your DTD doesn't already specify that then you might also want to change the DTD.]

See the Programmers Guide for a list of events you might wish to use for the script you end up coding. Most likely On_Click or On_Double_Click or perhaps you might wish to let the user run it from the context menu or using a shortcut key combination.

To let the user see the change without needing to have the Attribute Inspector open add something like the following to your CSS:

myElement:before {

I know I was playing around with something like this a few years ago that included images. Let me see if I can find whatever I was doing and turn it into a sample.

Note that in my examples above I'm using your names for the element and attribute.