I have a date input on a page. I pass the value entered in it to a function that will leave it alone or clear the date value in the component under certain conditions. When a user users the calendar to enter a date into the input, and clicks the validate button below, I just can’t get the function to clear the entered date value when required. The closest I could get is that “Invalid Date” appears in the input.
Thx for ideas.
Hello @musseman, thank you for your feedback.
I think there is a way to clear a variable by using a predefined function in code lines.
The predefined function is “clearVariable()
” as you can see in the documentation: Variables | Qodly Documentation
I give you an example:
The function above has one parameter that represents the date qodly source bound to the text input. I did the predefined function “clearVariable()
” to that variable if it is not empty, then I returned it as a result.
So, in the test, I select a date:
When I click on the button “Clear Date”, the input becomes empty:
Hope that this solution works on your side.
Best regards.
Thanks. Recommend clearVariable() be added to the commands section in the documentation as well.
Will try it out and report if issue, but imagine that will do the trick.
Thx.
Also-would be good if th calendar widget had a way for the user to self clear the date.
1 Like
The input is set as type date and format short date.
When the input is clicked into by the user a default Qodly calendar widget pops up
User selects a date using the widget.
The selected date appears in the input.
If the user clicks back into the input, they can only change the date with no option to just clear it. (unless i add a button, which is ok i guess.)
So 1: can their be a way for a user to self clear a dtate entered from that popup calndar widget?
2: Problem still not solved. I dont get blank input when I clear, i still get “Invalid Date” appearing in the input.
When user slects “No” form a select, the Date should be cleared:
exposed Function updatePODDOB (podtoggle:string, poddob:date)->result:date
result = podtoggle == “No” ? clearVariable(poddob) : poddob
When user selects “No” “Invalid Date” shows up in the date input.
No-code solution : you can define a Qodly source date set to an empty value and add a button with on click standard action that copies this empty date into the Qodly source linked to the date input you want to clear.
1 Like
I have solved it. I wish the solution were more intuitive, but..The approaches suggested, like the suggestion to try clearVariable(datevar) within the function, or copy the empty value of another date input to the subject input did not work. clearVariable(datevar) left the subject input (of type date and format short date) showing “Invalid Date”. When I attempted to clear it by copying a blank DATE into it: --the initial value of any standalone date input (ie not an object attribute) cannot be set to “”. It must be set to a date or just initialized with nothing as value. Copying it using standard action did not clear the value of the subject date input. strange, but…?
SOLUTION 1: The valid date attribute value of an object to be cleared comes into a function as a param, and the result can be EITHER an empty STRING or the valid DATE already in the attribute (in the case of this conditional clear value function.)
The result must be a VARIANT to make it work. It clears the input fine if the condition is met.
exposed Function updatePODDOB (podtoggle:string, pod_dob:date)->result:variant
var blankdate:string = “”
if(podtoggle == “No”)
result = blankdate
else
result = pod_dob
end
return result // result (is an Empty STRING or a valid DATE) is updated to the subject date input fine
It seems that object attributes intended to hold dates can hold dates or strings. Put a blank string in their to clear the input.
1 Like