Pages: 1
Print
Author Topic: can we create checkbox in xmetal  (Read 9469 times)
karthic2861
Member

Posts: 22


« on: April 25, 2012, 01:20:01 AM »

Hi all,

can we create checkbox in xmetal using javascript is that posible

if it is yes please advise me how to do?

Thanks
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #1 on: April 25, 2012, 03:35:51 AM »

Yes. But how to do this will depend on what you need the checkbox to do, where you need it to be displayed and how the user should be able to interact with it. What needs to happen when the checkbox is checked / unchecked? Presumably something will be done to the XML?

If you can provide those details I can probably point you in the right direction.
Logged
karthic2861
Member

Posts: 22


« Reply #2 on: April 25, 2012, 05:47:30 AM »

Hi Derek,

Can Xmetal represent an element like Checkbox?

e.g.

<myElement val = "1"/> rendered as checked checkbox
<myElement val = "0"/>rendered as unchecked checkbox

thanks
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #3 on: April 25, 2012, 12:11:03 PM »

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 "Forms" and "Create a form". 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 "Associate a form with a customization object" (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:

//JScript:
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 {
  content:attr(val);
}


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.
« Last Edit: April 25, 2012, 12:27:32 PM by Derek Read » Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #4 on: April 25, 2012, 01:17:29 PM »

I've found and cleaned up my sample. You might have a look: http://forums.xmetal.com/index.php/topic,2259

Note that it demonstrates a very specific case that sounds similar to what you seem to be asking for. You didn't provide too many details though so I am not certain that this is really what you need. Even if it is not useful for you others might use it for inspiration so I've created a new topic in the Tips and Tricks section for it.
Logged
karthic2861
Member

Posts: 22


« Reply #5 on: May 14, 2012, 04:18:42 AM »

Hi Derek,

Thanks for the wonderful sample.

Even i modified for single Click but still when i run that application in xmetal from your sample demo.

I am getting error as :

Line 2 . Column 0

Description : object required

Could you please guide me which JS have this error and how to solve.

Thanks
Maha

Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #6 on: May 14, 2012, 10:29:17 AM »

What have you modified that causes this error? This error means that there is a typo in the method you are calling or the property you are trying to set, or that the object (the thing you call methods on or set the properties of) does not exist.

So, basically I'd need to see your code in its present state to tell you what is broken.

You may also wish to pick up some books on JScript or scripting in general (Windows Script Host, JScript, VBScript, etc).
« Last Edit: May 14, 2012, 10:32:00 AM by Derek Read » Logged
karthic2861
Member

Posts: 22


« Reply #7 on: May 14, 2012, 11:17:56 AM »

Hi Derek ,

Thanks for the reply.

I didn't change much in your example (http://forums.xmetal.com/index.php/topic,2259). 
I just added a Macro file  On_click in that i  just call the function. Which i is been available in the onscript load file.js  Actually My requirement was so simple instead of double click just click  it was working but the error is causing with the example. (http://forums.xmetal.com/index.php/topic,2259) if you download the attachment what you provided me. The error was causing their I am sorry if I said anything wrong.

I am trying to identify but i was not able to it.

Please guide me here.

Thanks
Maha
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #8 on: May 14, 2012, 01:31:35 PM »

If you want the demo to run in On_Click instead of On_Double_Click you should be able to leave everything as it is but change the macro name from On_Double_Click to On_Click.

Of course, in real life nobody is going to use <tristate> and <bistate> as element names, so the demo isn't going to work with your schema (DTD or XSD) without further modifications. You will probably need to modify element and attribute names and even values to match whatever is in your schema.
« Last Edit: May 14, 2012, 01:37:38 PM by Derek Read » Logged
karthic2861
Member

Posts: 22


« Reply #9 on: May 15, 2012, 12:02:29 AM »

Hi derek,

I did in the same way only.  But still i am getting the error as object required.

The error is in the example itself I have not changed any dtd i am using wht u gave I need it for demo purpose i just kept as it is what u gave in the example.

Thanks
M
Logged
karthic2861
Member

Posts: 22


« Reply #10 on: May 15, 2012, 05:37:47 AM »

Hi Derek,

I solved that issue.

Thank you very much for your support.

Regards
M
Logged
mjkhan
Member

Posts: 20


« Reply #11 on: August 28, 2012, 03:31:31 PM »

Hi Derek,
We have similar situation where the tag with 0 or 1 value needs to be shown as YES/NO options on the XMetal UI. Is there anyway to do this? User does not want to see 0/1 on the screen. So following tag in the content needs to be shown as YES/NO option.

<myelem>0</myelem> (show as NO)
OR
<myelem>1</myelem> (show as YES)

I can do this with XFT dialog but user would prefer not to invoke dialog box. Also, not sure how to show yes/no instead of 0/1 on screen. Is there way to do this?

Thanks
Mahmood
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #12 on: August 28, 2012, 04:48:34 PM »

The strategy would be pretty much identical if you don't want to use XFT. You would just need to modify the script and CSS appropriately.

Instead of displaying an image for the CSS as in my example you would display text using content:"yes" or content:"no" within appropriate selectors.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2505



WWW
« Reply #13 on: August 28, 2012, 04:51:52 PM »

Sorry, just realized that you don't have any way to build a selector that will differentiate between the two different elements since it is their content (PCDATA) that differentiates them and not attributes. There is no way to do that in CSS.

In this case XFT is probably the easiest way to give the user the UI they want. However, instead of using modal XFT dialog you could display it embedded. Be careful that your documents won't embed too many though as doing so can slow editing and rendering down (depending on what the XFT contains and how many there are).

One alternative I would consider the better option would be to use the SetRenderedContent() API. See the Journalist demo which uses this API for the <PubDate> element (allowed just after Article>Title as a sibling to Title).

In that demo, if <PubDate> is stored as <PubDate>20120725</PubDate> in the XML then when that is rendered in Tags On or Normal view the journalist.mcr file uses SetRenderedContent() to show the user the date in this form:
<PubDate>Publication Date: July 25th, 2012</PubDate>
« Last Edit: August 28, 2012, 04:58:39 PM by Derek Read » Logged
mjkhan
Member

Posts: 20


« Reply #14 on: August 29, 2012, 11:15:49 AM »

Thanks Derek! This is very helpful. I tried it and it is exactly what I needed.
Logged
Pages: 1
Print
Jump to: