Dropdown question on pespective view

dropdown add and remove
to add you can
droplist =
droplist.append({'label':'hello','value':1})
droplist.append({'label':'hello2','value':2})
self.getSibling('Dropdown').props.options = droplist

The syntax to remove is
dropdown = self.getSibling('Dropdown')
if "option_you_want_to_remove" in dropdown.props.options:
dropdown.props.options.remove("option_you_want_to_remove")

I can not figure how to option_you_want_to_remove format and how would
you know what option_you_want_to_remove would be

Hi, Donald. Please see Wiki - how to post code on this forum and hit the pencil icon to edit your post. Otherwise we don't know if it's indented properly.

Meanwhile, try the code below in Script Console.

Script Console demonstration
true = True
false = False

input = [
  {
    "value": 0,
    "label": "Option 0",
    "isDisabled": false
  },
  {
    "value": 1,
    "label": "Option 1",
    "isDisabled": false
  },
  {
    "value": 2,
    "label": "Option 2",
    "isDisabled": false
  },
  {
    "value": 3,
    "label": "Option 3",
    "isDisabled": false
  },
  {
    "value": 4,
    "label": "Option 4",
    "isDisabled": false
  },
  {
    "value": 5,
    "label": "Option 5",
    "isDisabled": false
  }
]

valueToBeRemoved = 4
output = []
for option in input:
	print option
	if not option['value'] == valueToBeRemoved:
		output.append(option)
		
print output

(But please fix the formatting in your question. It may help someone in the future.)

not what I am looking for

OK. You haven't explained what's wrong with my answer and you don't seem to be interested in contributing on the site. I don't think I can help further.

first I thought you were an AI type auto responder. Second I was looking on what the syntax was for the remove command. It would seem you would need to grab the dropdown list entries before you would know the string to look for. I have accessed the manual but as normal it is vague and does not cover all the options with examples.
So if you append the dropdown with
droplist.append({'label':'hello','value':1})
and use the comand
dropdown.props.options.remove("option_you_want_to_remove")
how do you know what should replace "option_you_want_to_remove"
with out scanning the list to begin with cause It is not using input command and your example does not use the remove command

Hi Donald,

How are you getting the 'option_you_want_to_remove', is this just the selected option in the dropdown or is it being populated from somewhere else?

Assuming you know what the 'option_you_want_to_remove' is you can traverse the array, find the index (if the option exists) and then use the .pop(index) function to remove that instance.
Python Arrays is a good resource for array manipulation.

As Transistor mentioned, please post code on the forums in the proper format so we can easily follow it.

There are many examples on the Internet. Try a good ole Goog. Your question isn't as much an Ignition thing as it is Python/Jython.

it was supplied by Ignition as an example

this is what they supplied

Hi Donald, do you have a link to the example we can review?

typical

For anyone considering trying to assist on this thread I recommend a browse through previous "contributions". It's not nice.

2 Likes

Indeed. I remember some of that.

This advice from one of those seems applicable:

@Donald_Dahlman : Perhaps you should open a support ticket, so someone gets paid to help you. This forum is full of volunteers who don't have to put up with your [expletive].

3 Likes