Highlighted

Nested dialogue problem

Advocate ,
Oct 10, 2016

Copy link to clipboard

Copied

Dear experts,
From a palette i need to divert into a dialgoue and then come back into the palette.
This works fine for the first time i enter the dialogue. The dialogue fails when entered the second time.
A stripped down version of my scripts is following. The palette is to the left, the 'test' dialogue to the right:

dialogues.png

  • Usage is as follows:
  • In the palette active the checkbox and clik the Handle Content button.
  • This invokes the 'test' dialogue.
  • According to the settings in the script the OK/Return button is hidden.
  • Clicking the Cancel button closes this dialogue and we are back in the palette.
  • Since the 'test' was cancelled, an alert appears with NO as default.
  • Click NO
  • The check box is cleared for a new decision
  • Now the user 'changes the input (top field)', checks the box and clicks the Handle ... button.
  • => Error on line 48: undefined is not an object.

What may be wrong here?

// NestedDialogue.jsx
#target framemaker
// target needed for Alert ...
var gsVariable;
var wPalDS = new Window('palette',"FM-calc : Manage Variables",undefined);
var wPalV  = new Window('dialog', "FM-calc : Check contents of variable", undefined);

PaletteDocSettings();
// ================================================================================================
function PaletteDocSettings(){ //=== Outer function
    wPalDS.sVarValue = wPalDS.add('edittext',undefined,"Content to be handled", {multiline:true});
    wPalDS.sVarValue.alignment = ['right',' '];

    wPalDS.cbChkContent = wPalDS.add('checkbox',undefined,"Use secondary dialogue");
 
    wPalDS.btnAdd = wPalDS.add('button',undefined,"Handle content");
  wPalDS.Cancel = wPalDS.add('button',undefined,"Cancel");

  wPalDS.Cancel.onClick = function () {
    wPalDS.close(); 
  }
    wPalDS.btnAdd.onClick = ButtonAddVarConst;    // externalised callback function!

 
  wPalDS.show();
} //---  end PaletteDocSettings

function ButtonAddVarConst () {
var bContinue, content;
// $.bp(true);
  content =  wPalDS.sVarValue.text;
  if (wPalDS.cbChkContent.value) {  // check contents
    gsVariable = "=" + content;
    DialogueVerify();                             // Inner function
    bContinue = wPalV.btnReturn.enabled;
    if (!bContinue) {
      if (Alert ("Test failed, continue anyway?", Constants.FF_ALERT_NO_DEFAULT) != 0) {
        wPalDS.cbChkContent.value = false;        // uncheck
        return;                                   // user clicked NO
      }
    }
    content = gsVariable.substring (1);         // skip the = sign
    wPalDS.sVarValue.text = content;
  }
} //--- end ButtonAddVarConst

function DialogueVerify(){ //=== Dialogue for verifying variable contents
  wPalV.st1 = wPalV.add('statictext',undefined,"Content to check");
  wPalV.st1.graphics.font = ScriptUI.newFont(wPalV.st1.graphics.font.family,"BOLD",wPalV.st1.graphics.font.size);

  wPalV.btnReturn = wPalV.add('button',undefined,"OK / Return");
  wPalV.btnReturn.helpTip = "Return to calling dialogue";

  wPalV.Cancel = wPalV.add('button',undefined,"Cancel");
  wPalV.Cancel.alignment = ['right',' '];

  wPalV.btnReturn.onClick =   ButtonReturnV;   // externalised callback function!

  wPalV.Cancel.onClick = function () {
    wPalV.close();
  }
  wPalV.btnReturn.enabled = false;             // test situation 1 (using Cancel to exit)
//wPalV.btnReturn.enabled = true;              // test situation 2 (using this button to exit)
  wPalV.show();
}

function ButtonReturnV () {
  wPalV.close();
} //---  end ButtonReturnV

Any ideas are welcome ...

Trying various modification I have found a solution:

  • The secondary (nested) dialogue must not use a global definition for the window. It must be within the routine (see line 49).
  • tDue to this the status of the Cancel button is not known outside of wPalV. Hence I need the global variable reflecting it (lines 07, 36, 61)

With this knowledge I will modify the full-blown script and hope that it works also...

This works as intended:

// NestedDialogue.jsx
#target framemaker
// target needed for Alert ...xxx

var gsVariable;
var wPalDS = new Window('palette',"FM-calc : Manage Variables",undefined);
var gbOK   = false;

PaletteDocSettings();

// ================================================================================================
function PaletteDocSettings(){ //=== Outer function
    wPalDS.sVarValue = wPalDS.add('edittext',undefined,"Content to be handled", {multiline:true});
    wPalDS.sVarValue.alignment = ['right',' '];

    wPalDS.cbChkContent = wPalDS.add('checkbox',undefined,"Use secondary dialogue");
 
    wPalDS.btnAdd = wPalDS.add('button',undefined,"Handle content");
  wPalDS.Cancel = wPalDS.add('button',undefined,"Cancel");

  wPalDS.Cancel.onClick = function () {
    wPalDS.close(); 
  }
    wPalDS.btnAdd.onClick = ButtonAddVarConst;  
 
  wPalDS.show();
} //---  end PaletteDocSettings

function ButtonAddVarConst () {
var bContinue, content;
  content =  wPalDS.sVarValue.text;
  if (wPalDS.cbChkContent.value) {  // check contents
    gsVariable = "=" + content;
      DialogueVerify();                           // Inner function
//  bContinue = wPalV.btnReturn.enabled;
    bContinue = gbOK;
    if (!bContinue) {
      if (Alert ("Test failed, continue anyway?", Constants.FF_ALERT_NO_DEFAULT) != 0) {
        wPalDS.cbChkContent.value = false;        // uncheck
        return;                                   // user clicked NO
      }
    }
    content = gsVariable.substring (1);           // skip the = sign
    wPalDS.sVarValue.text = content;
  }
} //--- end ButtonAddVarConst

function DialogueVerify(){ //=== Dialogue for verifying variable contents
var wPalV  = new Window('dialog', "FM-calc : Check contents of variable", undefined);
    wPalV.st1 = wPalV.add('statictext',undefined,"Content to check");
  wPalV.st1.graphics.font = ScriptUI.newFont(wPalV.st1.graphics.font.family,"BOLD",wPalV.st1.graphics.font.size);

    wPalV.btnReturn = wPalV.add('button',undefined,"OK / Return");
    wPalV.btnReturn.helpTip = "Return to calling dialogue";

    wPalV.Cancel = wPalV.add('button',undefined,"Cancel");
    wPalV.Cancel.alignment = ['right',' '];

  wPalV.btnReturn.enabled = false;                // test situation 1 (using Cancel to exit)
//wPalV.btnReturn.enabled = true;                 // test situation 2 (using this button to exit)
  gbOK = false;                                   // Outside there is not access to wPalV objects

  wPalV.btnReturn.onClick = function () {
    wPalV.close();
  }

  wPalV.Cancel.onClick = function () {
    wPalV.close();
  }
  wPalV.show();
}

TOPICS
Scripting

Views

268

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Nested dialogue problem

Advocate ,
Oct 10, 2016

Copy link to clipboard

Copied

Dear experts,
From a palette i need to divert into a dialgoue and then come back into the palette.
This works fine for the first time i enter the dialogue. The dialogue fails when entered the second time.
A stripped down version of my scripts is following. The palette is to the left, the 'test' dialogue to the right:

dialogues.png

  • Usage is as follows:
  • In the palette active the checkbox and clik the Handle Content button.
  • This invokes the 'test' dialogue.
  • According to the settings in the script the OK/Return button is hidden.
  • Clicking the Cancel button closes this dialogue and we are back in the palette.
  • Since the 'test' was cancelled, an alert appears with NO as default.
  • Click NO
  • The check box is cleared for a new decision
  • Now the user 'changes the input (top field)', checks the box and clicks the Handle ... button.
  • => Error on line 48: undefined is not an object.

What may be wrong here?

// NestedDialogue.jsx
#target framemaker
// target needed for Alert ...
var gsVariable;
var wPalDS = new Window('palette',"FM-calc : Manage Variables",undefined);
var wPalV  = new Window('dialog', "FM-calc : Check contents of variable", undefined);

PaletteDocSettings();
// ================================================================================================
function PaletteDocSettings(){ //=== Outer function
    wPalDS.sVarValue = wPalDS.add('edittext',undefined,"Content to be handled", {multiline:true});
    wPalDS.sVarValue.alignment = ['right',' '];

    wPalDS.cbChkContent = wPalDS.add('checkbox',undefined,"Use secondary dialogue");
 
    wPalDS.btnAdd = wPalDS.add('button',undefined,"Handle content");
  wPalDS.Cancel = wPalDS.add('button',undefined,"Cancel");

  wPalDS.Cancel.onClick = function () {
    wPalDS.close(); 
  }
    wPalDS.btnAdd.onClick = ButtonAddVarConst;    // externalised callback function!

 
  wPalDS.show();
} //---  end PaletteDocSettings

function ButtonAddVarConst () {
var bContinue, content;
// $.bp(true);
  content =  wPalDS.sVarValue.text;
  if (wPalDS.cbChkContent.value) {  // check contents
    gsVariable = "=" + content;
    DialogueVerify();                             // Inner function
    bContinue = wPalV.btnReturn.enabled;
    if (!bContinue) {
      if (Alert ("Test failed, continue anyway?", Constants.FF_ALERT_NO_DEFAULT) != 0) {
        wPalDS.cbChkContent.value = false;        // uncheck
        return;                                   // user clicked NO
      }
    }
    content = gsVariable.substring (1);         // skip the = sign
    wPalDS.sVarValue.text = content;
  }
} //--- end ButtonAddVarConst

function DialogueVerify(){ //=== Dialogue for verifying variable contents
  wPalV.st1 = wPalV.add('statictext',undefined,"Content to check");
  wPalV.st1.graphics.font = ScriptUI.newFont(wPalV.st1.graphics.font.family,"BOLD",wPalV.st1.graphics.font.size);

  wPalV.btnReturn = wPalV.add('button',undefined,"OK / Return");
  wPalV.btnReturn.helpTip = "Return to calling dialogue";

  wPalV.Cancel = wPalV.add('button',undefined,"Cancel");
  wPalV.Cancel.alignment = ['right',' '];

  wPalV.btnReturn.onClick =   ButtonReturnV;   // externalised callback function!

  wPalV.Cancel.onClick = function () {
    wPalV.close();
  }
  wPalV.btnReturn.enabled = false;             // test situation 1 (using Cancel to exit)
//wPalV.btnReturn.enabled = true;              // test situation 2 (using this button to exit)
  wPalV.show();
}

function ButtonReturnV () {
  wPalV.close();
} //---  end ButtonReturnV

Any ideas are welcome ...

Trying various modification I have found a solution:

  • The secondary (nested) dialogue must not use a global definition for the window. It must be within the routine (see line 49).
  • tDue to this the status of the Cancel button is not known outside of wPalV. Hence I need the global variable reflecting it (lines 07, 36, 61)

With this knowledge I will modify the full-blown script and hope that it works also...

This works as intended:

// NestedDialogue.jsx
#target framemaker
// target needed for Alert ...xxx

var gsVariable;
var wPalDS = new Window('palette',"FM-calc : Manage Variables",undefined);
var gbOK   = false;

PaletteDocSettings();

// ================================================================================================
function PaletteDocSettings(){ //=== Outer function
    wPalDS.sVarValue = wPalDS.add('edittext',undefined,"Content to be handled", {multiline:true});
    wPalDS.sVarValue.alignment = ['right',' '];

    wPalDS.cbChkContent = wPalDS.add('checkbox',undefined,"Use secondary dialogue");
 
    wPalDS.btnAdd = wPalDS.add('button',undefined,"Handle content");
  wPalDS.Cancel = wPalDS.add('button',undefined,"Cancel");

  wPalDS.Cancel.onClick = function () {
    wPalDS.close(); 
  }
    wPalDS.btnAdd.onClick = ButtonAddVarConst;  
 
  wPalDS.show();
} //---  end PaletteDocSettings

function ButtonAddVarConst () {
var bContinue, content;
  content =  wPalDS.sVarValue.text;
  if (wPalDS.cbChkContent.value) {  // check contents
    gsVariable = "=" + content;
      DialogueVerify();                           // Inner function
//  bContinue = wPalV.btnReturn.enabled;
    bContinue = gbOK;
    if (!bContinue) {
      if (Alert ("Test failed, continue anyway?", Constants.FF_ALERT_NO_DEFAULT) != 0) {
        wPalDS.cbChkContent.value = false;        // uncheck
        return;                                   // user clicked NO
      }
    }
    content = gsVariable.substring (1);           // skip the = sign
    wPalDS.sVarValue.text = content;
  }
} //--- end ButtonAddVarConst

function DialogueVerify(){ //=== Dialogue for verifying variable contents
var wPalV  = new Window('dialog', "FM-calc : Check contents of variable", undefined);
    wPalV.st1 = wPalV.add('statictext',undefined,"Content to check");
  wPalV.st1.graphics.font = ScriptUI.newFont(wPalV.st1.graphics.font.family,"BOLD",wPalV.st1.graphics.font.size);

    wPalV.btnReturn = wPalV.add('button',undefined,"OK / Return");
    wPalV.btnReturn.helpTip = "Return to calling dialogue";

    wPalV.Cancel = wPalV.add('button',undefined,"Cancel");
    wPalV.Cancel.alignment = ['right',' '];

  wPalV.btnReturn.enabled = false;                // test situation 1 (using Cancel to exit)
//wPalV.btnReturn.enabled = true;                 // test situation 2 (using this button to exit)
  gbOK = false;                                   // Outside there is not access to wPalV objects

  wPalV.btnReturn.onClick = function () {
    wPalV.close();
  }

  wPalV.Cancel.onClick = function () {
    wPalV.close();
  }
  wPalV.show();
}

TOPICS
Scripting

Views

269

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 10, 2016 0
Advocate ,
Oct 10, 2016

Copy link to clipboard

Copied

Hello Klaus,

Just move the entire function ButtonReturnV up a couple of lines so that it is inside the function body of the DialogueVerify function. I am not sure why you externalize it, but it seems to throw off the link between the calling dialog and the external function that is working on it.

Kind regards

Jang

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 10, 2016 0
Advocate ,
Oct 10, 2016

Copy link to clipboard

Copied

Hi Jang,

It would have been too simple - but the result is the same as with the externalised call-back function: tilt in line 48.

The changed lines from 58 downwards:

wPalV.btnReturn.onClick = function () {
    wPalV.close();
  }

  wPalV.Cancel.onClick = function () {
    wPalV.close();
  }
  wPalV.btnReturn.enabled = false;            // test situation 1 (using Cancel to exit)
//wPalV.btnReturn.enabled = true;              // test situation 2 (using this button to exit)
  wPalV.show();
}

Reading Peter Kahrel's pdf about ScriptUI back and forth did not provide the magic information. From a mentioned link (Calling functions from UI palette) I also did not get a clue.

Taking a break of 4 days now - maybe new ideas will ripe.

Klaus

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 10, 2016 0
Advocate ,
Oct 17, 2016

Copy link to clipboard

Copied

Trying various modification I have found a solution:

  • The secondary (nested) dialogue must not use a global definition for the window. It must be within the routine (see line 49).
  • tDue to this the status of the Cancel button is not known outside of wPalV. Hence I need the global variable reflecting it (lines 07, 36, 61)

With this knowledge I will modify the full-blown script and hope that it works also...

This works as intended:

// NestedDialogue.jsx
#target framemaker
// target needed for Alert ...xxx

var gsVariable;
var wPalDS = new Window('palette',"FM-calc : Manage Variables",undefined);
var gbOK   = false;

PaletteDocSettings();

// ================================================================================================
function PaletteDocSettings(){ //=== Outer function
    wPalDS.sVarValue = wPalDS.add('edittext',undefined,"Content to be handled", {multiline:true});
    wPalDS.sVarValue.alignment = ['right',' '];

    wPalDS.cbChkContent = wPalDS.add('checkbox',undefined,"Use secondary dialogue");
 
    wPalDS.btnAdd = wPalDS.add('button',undefined,"Handle content");
  wPalDS.Cancel = wPalDS.add('button',undefined,"Cancel");

  wPalDS.Cancel.onClick = function () {
    wPalDS.close(); 
  }
    wPalDS.btnAdd.onClick = ButtonAddVarConst;  
 
  wPalDS.show();
} //---  end PaletteDocSettings

function ButtonAddVarConst () {
var bContinue, content;
  content =  wPalDS.sVarValue.text;
  if (wPalDS.cbChkContent.value) {  // check contents
    gsVariable = "=" + content;
      DialogueVerify();                           // Inner function
//  bContinue = wPalV.btnReturn.enabled;
    bContinue = gbOK;
    if (!bContinue) {
      if (Alert ("Test failed, continue anyway?", Constants.FF_ALERT_NO_DEFAULT) != 0) {
        wPalDS.cbChkContent.value = false;        // uncheck
        return;                                   // user clicked NO
      }
    }
    content = gsVariable.substring (1);           // skip the = sign
    wPalDS.sVarValue.text = content;
  }
} //--- end ButtonAddVarConst

function DialogueVerify(){ //=== Dialogue for verifying variable contents
var wPalV  = new Window('dialog', "FM-calc : Check contents of variable", undefined);
    wPalV.st1 = wPalV.add('statictext',undefined,"Content to check");
  wPalV.st1.graphics.font = ScriptUI.newFont(wPalV.st1.graphics.font.family,"BOLD",wPalV.st1.graphics.font.size);

    wPalV.btnReturn = wPalV.add('button',undefined,"OK / Return");
    wPalV.btnReturn.helpTip = "Return to calling dialogue";

    wPalV.Cancel = wPalV.add('button',undefined,"Cancel");
    wPalV.Cancel.alignment = ['right',' '];

  wPalV.btnReturn.enabled = false;                // test situation 1 (using Cancel to exit)
//wPalV.btnReturn.enabled = true;                 // test situation 2 (using this button to exit)
  gbOK = false;                                   // Outside there is not access to wPalV objects

  wPalV.btnReturn.onClick = function () {
    wPalV.close();
  }

  wPalV.Cancel.onClick = function () {
    wPalV.close();
  }
  wPalV.show();
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 17, 2016 0