Skip to main content
K.Daube
Community Expert
Community Expert
March 12, 2021
Answered

How to de-select in a list box

  • March 12, 2021
  • 1 reply
  • 333 views

Dear friends, maybe I'm blindfolded.

I fill an EditText field with selections from ListBoxes. Whether I do this by a callback function onClick or onDoubleClick, the selection is persistent:

Relevant script parts:

 

 

  wPalR.g1b.lstChars.onDoubleClick = function () {
    KLD_F.InsertEditItem (wPalR.g1b.lstChars, KLD_F.aLstChars, wPalR.g3.eReg);
  };

KLD_F.InsertEditItem = function (oList, asItems, oEdit) {
var index, iTab, strLen, sItem;
  index = oList.selection.valueOf();
  iTab = asItems[index].indexOf("¦");
  sItem = asItems[index].substring (iTab+1);
  oEdit.textselection = sItem;
} // --- end InsertEditItem 

 

 

 

This topic has been closed for replies.
Correct answer Klaus Göbel

Good morning,

if I have understood you correctly, you want to deselect a listitem.

Just do this: List.selection.index = null

Here's an example how to select or deselect listitems (multiselect:no)

 

#target framemaker
"use strict";
#strict on

var oDia = new Window("dialog","TEST",undefined);
var aContent1 = ["Andorra","Belgium","Chile","Denmark"];

var oDiaFrame = oDia.add("group",undefined,aContent1);
var dList = oDiaFrame.add("listbox",undefined,aContent1);
dList.selection = 2;

var Button1 = oDiaFrame.add("button",undefined,"de-select",{name:"deselect"});
Button1.onClick = Deselection;

var Button2 = oDiaFrame.add("button",undefined,"select next",{name:"next"})
Button2.onClick = SelectNext;

var Button3 = oDiaFrame.add("button",undefined,"select prev",{name:"prev"})
Button3.onClick = SelectPrev;

oDia.show();

function Deselection()
{
dList.selection = null;
}

function SelectNext()
{
    if (dList.selection.index == null)
        {
         NDX = 0;   
        }
    else
        {
         NDX = dList.selection.index + 1
        }
    
        
     if (NDX >= dList.children.length)
        {
         NDX = 0;   
        }

    
dList.selection = NDX;
}

function SelectPrev()
{
    var NDX;
    
    if (dList.selection.index == null)
        {
         NDX = 0;   
        }
    else
        {
         NDX = dList.selection.index - 1
        }
    if (NDX < 0)
        {
         NDX = dList.children.length -1;
        }
dList.selection = NDX;
}

1 reply

Klaus Göbel
Klaus GöbelCorrect answer
Legend
March 13, 2021

Good morning,

if I have understood you correctly, you want to deselect a listitem.

Just do this: List.selection.index = null

Here's an example how to select or deselect listitems (multiselect:no)

 

#target framemaker
"use strict";
#strict on

var oDia = new Window("dialog","TEST",undefined);
var aContent1 = ["Andorra","Belgium","Chile","Denmark"];

var oDiaFrame = oDia.add("group",undefined,aContent1);
var dList = oDiaFrame.add("listbox",undefined,aContent1);
dList.selection = 2;

var Button1 = oDiaFrame.add("button",undefined,"de-select",{name:"deselect"});
Button1.onClick = Deselection;

var Button2 = oDiaFrame.add("button",undefined,"select next",{name:"next"})
Button2.onClick = SelectNext;

var Button3 = oDiaFrame.add("button",undefined,"select prev",{name:"prev"})
Button3.onClick = SelectPrev;

oDia.show();

function Deselection()
{
dList.selection = null;
}

function SelectNext()
{
    if (dList.selection.index == null)
        {
         NDX = 0;   
        }
    else
        {
         NDX = dList.selection.index + 1
        }
    
        
     if (NDX >= dList.children.length)
        {
         NDX = 0;   
        }

    
dList.selection = NDX;
}

function SelectPrev()
{
    var NDX;
    
    if (dList.selection.index == null)
        {
         NDX = 0;   
        }
    else
        {
         NDX = dList.selection.index - 1
        }
    if (NDX < 0)
        {
         NDX = dList.children.length -1;
        }
dList.selection = NDX;
}
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
March 13, 2021

Thanks Klaus, again a very simple solution to an envsioned problem:

 

List.selection.index = null

 

index is a property of the list item - which is not that obvious...

Sorry, that missed the target, but led me to the correct solution:

List.selection.selected= false;