I want to check whether user picked date from datetime input component on a button click
I tried following codes:
if isNull(self.session.custom.expenseSelectDate):
if self.session.custom.expenseSelectDate == null:
if self.session.custom.expenseSelectDate == “null”:
if self.session.custom.expenseSelectDate == “”:
if self.session.custom.expenseSelectDate == 0:
none of them seems wokring
Thank you.
Try just if self.session.custom.expenseSelectDate:
.
Python uses the special singleton instance None
to represent no value/null.
Literal null
is a syntax error unless you’ve defined a variable null
in scope.
== "null"
is comparing against the literal string "null"
.
== ""
is comparing against an empty string.
== 0
is checking for exact equality with 0; not a ‘falsey’ comparison.
If you omit all operators, Python’s if
statement automatically checks for ‘truth’; the following statements are essentially equivalent:
x = 1
if True:
if x:
if x == True:
if bool(x):
if bool(x) == True:
Python’s None
singleton is ‘falsey’, so you can simply:
if x:
Which will fail if x is None. Or, the recommended style, which is more explicit:
if x is not None:
You might want to add some logging so you can see what you really have in self.session.custom.expenseSelectDate
.
Its changing color as required on submit since its checking for true condition i want to check for false condition, how can i do that ?
its null in log there were no errors
Use not
:
if not self.session.custom.expenseSelectDate:
# do something if it's not set
1 Like
this worked for me:
if self.session.custom.expenseSelectDate is None:
Thank you
1 Like