General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion XFT forms with conditions

  • esha

    XFT forms with conditions

    Participants 4
    Replies 5
    Last Activity 12 years, 8 months ago

    Hello all

    I am new in XMetal development, and I am new to this forum also.
    So, Hello ALL…..

    I am trying to create a customisation using XMetal Developer(5.1) and VS 2008.

    I have a requirement to make conditional forms. ie, two forms to be displayed based on some condition for the same element. I need to display the attribute values using XFT forms.

    My DTD looks something like this::


    A NUMBER #IMPLIED
    B NUMBER #IMPLIED
    C NUMBER #IMPLIED
    D NUMBER #IMPLIED>

    Case 1 : XYZ has a form that takes values for A,B,C
    Case 2 : XYZ has a form that takes values for A,D

    Is this possible? If yes, how?? If no, what is the alternative?
    Anyone faced this situation? Pleasee help !

    Thanks

    Reply

    Derek Read

    Reply to: XFT forms with conditions

    I guess what you are asking is going to be possible, but I don't see anything that allows a decision to be made automatically here. I don't see a difference between the two cases, there's just one element here.

    From what you've got so far I think you'd need to prompt the user to ask them which form they want to display, or create two different forms and a user interface (menu item or toolbar button) that launches each form.

    Is that what you are looking for?

    Or maybe what you're saying is that if the element has attributes A,B,C set then launch form version 1, and if it has attributes A,D set then launch for version 2. Which form is launched for other cases? Or is this a complete misunderstanding?

    Reply

    esha

    Reply to: XFT forms with conditions

    Hey Derek, thanks for the response.

    I have two different forms for the same element. But, am confused on how to link them.
    I intend to use these forms to populate the attribute values for the same element.

    So, in my case 1, XYZ will not have an attribute D and in case 2, it will not have B,C.
    I can also create a user input interface (alerts, buttons) to decide which case to go with, but can you please tell me how to link it to element “XYZ”.
    Right now, I have 2 modal forms;how do I associate them with “XYZ”??Is it in the “CTM” file?If so, how? Please explain..

    Thanks again.
    Cheers!

    Reply

    Derek Read

    Reply to: XFT forms with conditions

    Linking two forms to the same element in the CTM file is not recommended as there really is no way for the product to know which one to display. You will really need something unique in order to decide which one to show the user.

    The following is one option:

    1. Create two macros each containing script similar to the following:
    [code]// XMetaL Script Language JSCRIPT:
    if (Selection.ContainerName == “XYZ”) {
    var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form1.xft”);
    dlg.DoModal();
    dlg=null;
    }
    else {
      //optional message:
      Application.Alert(“You must be inside an XYZ element to run this macro.”);
    }[/code]

    [code]// XMetaL Script Language JSCRIPT:
    if (Selection.ContainerName == “XYZ”) {
      var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form2.xft”);
      dlg.DoModal();
      dlg=null;
    }
    else {
      //optional message:
      Application.Alert(“You must be inside an XYZ element to run this macro.”);
    }[/code]

    2. Place your forms (form1.xft and form2.xft) inside the Forms folder and have your user run each of the macros depending on what they wish to do. You can give the macros appropriate names or associate them with nice buttons and put them on a toolbar or maybe add them to a menu, create a new menu, or add new items to the context menu. If you want to store these forms elsewhere adjust the code so the CreateFormDlg API can find them.

    If there is something unique about the element, you could have one script that decides which form to launch based on some basic logic as in this example:
    [code]// XMetaL Script Language JSCRIPT:
    if (Selection.ContainerName == “XYZ”) {
      if (Selection.ContainerAttribute(“A”) == “1”) {
        var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form1.xft”);
      }
      else {
        //attribute A is anything other than “1” or not set at all
        var dlg=Application.CreateFormDlg(Application.Path + “\Forms\form2.xft”);
      }
      dlg.DoModal();
      dlg=null;
    }
    else {
      //optional message:
      Application.Alert(“You must be inside an XYZ element to run this macro.”);
    }[/code]

    I think this is more of a question of deciding how you wish the application to decide which form to launch (and less of a programming issue). I think once you figure that out we can probably help (rather than taking guesses). Maybe step back and ask yourself how you (as a human) would decide which one to launch.

    It may also help to see some real XML in this case as well rather than dummy element, attribute names and values.

    Reply

    esha

    Reply to: XFT forms with conditions

    Thanks again Derek.

    I was trying to use the CTM file with some script code and forms for this, which didnt work.

    Now, I guess I can use the code in a macro and invoke the two forms which I need.
    Here, I understand that the values of my attributes will be extracted from the macro code and not using the XPATH setting in the form. Can you please confirm?
    Also, is there some method for having “Embedded” forms, and not “Modal” forms for this case?

    Reply

    Derek Read

    Reply to: XFT forms with conditions

    Having two different forms doesn't mean you can't use the XFT XPath property to automatically set the value.

    You would need to use modal forms in this case. You cannot have two forms embedded for one element.

    It still isn't clear to me why you would want to have two different forms for one element. What I'm thinking at this point is that maybe is that you really should only have one form, but have multiple controls on it (one for each attribute). If you can do that that would be best for everyone (XMetaL, you implementing it and your users). Perhaps you don't realize that a single form can have as many controls on it as you like?

    Reply

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

Lost Your Password?

Products
Downloads
Support