General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion can we create checkbox in xmetal

  • karthic2861

    can we create checkbox in xmetal

    Participants 13
    Replies 14
    Last Activity 10 years, 5 months ago

    Hi all,

    can we create checkbox in xmetal using javascript is that posible

    if it is yes please advise me how to do?

    Thanks

    Reply

    Derek Read

    Reply to: can we create checkbox in xmetal

    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.

    Reply

    karthic2861

    Reply to: can we create checkbox in xmetal

    Hi Derek,

    Can Xmetal represent an element like Checkbox?

    e.g.

    rendered as checked checkbox
    rendered as unchecked checkbox

    thanks

    Reply

    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:

    //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.

    Reply

    Derek Read

    Reply to: can we create checkbox in xmetal

    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.

    Reply

    karthic2861

    Reply to: can we create checkbox in xmetal

    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

    Reply

    Derek Read

    Reply to: can we create checkbox in xmetal

    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).

    Reply

    karthic2861

    Reply to: can we create checkbox in xmetal

    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

    Reply

    Derek Read

    Reply to: can we create checkbox in xmetal

    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 and 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.

    Reply

    karthic2861

    Reply to: can we create checkbox in xmetal

    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

    Reply

    karthic2861

    Reply to: can we create checkbox in xmetal

    Hi Derek,

    I solved that issue.

    Thank you very much for your support.

    Regards
    M

    Reply

    mjkhan

    Reply to: can we create checkbox in xmetal

    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.

    0 (show as NO)
    OR
    1 (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

    Reply

    Derek Read

    Reply to: can we create checkbox in xmetal

    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.

    Reply

    Derek Read

    Reply to: can we create checkbox in xmetal

    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 element (allowed just after Article>Title as a sibling to Title).

    In that demo, if is stored as 20120725 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:
    Publication Date: July 25th, 2012

    Reply

    mjkhan

    Reply to: can we create checkbox in xmetal

    Thanks Derek! This is very helpful. I tried it and it is exactly what I needed.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support