I’m just writing a simple ‘if’ loop to check the content of dropdown value and popup a message to user if the content is empty when they press submit button. Since the dropdown menu has clear button on it, when we clear the button the dropdown value becomes null.
I need syntax to check the null value in this dropdown component.
I used following syntax but getting error message.
if self.getSibling(“Dropdown”).props.value == “”:
if self.getSibling(“Dropdown”).props.value == “null”:
if self.getSibling(“Dropdown”).props.value == null:
Dear Deon,
Thanks for prompt response.
Provided syntax works well when the dropdown.props.value is null (that is whenever I select one value in dropdown and clear the content, dropdown.props.value is null and syntax works).
But during the session starup or view switchover, the dropdown.props.value is blank, hence the above syntax didnt solve my problem completely.
However I created a custom value as selected label and used the syntax you provided, it works well and solved my issue.
For custom selectedlabel I followed this recommendation:
Syntax I used as:
self.getSibling("Dropdown").custom.selectedlabel == None:
Should probably work. Python’s singleton for null, None, is evaluated as False, as is an empty string "", so a simple if statement will only pass if there is at least one character in the string.
The following code will work to determine if your Dropdown has no current selection:
(self.props.value is None) or (len(self.props.value) == 0)
Scripting uses Jython, which uses Python’s None instead of Java’s null.
From your listed attempts:
if self.getSibling("Dropdown").props.value == null:
# this will NEVER work in Ignition because it will treat null as a variable
if self.getSibling("Dropdown").props.value == "null":
# this will only ever work if you supply a String with a value of "null"
if self.getSibling("Dropdown").props.value == "":
# this will work if no option is selected, unless you use the "clear" option, at which point you need the None option I supplied you.