Android Question [Solved] B4XDateTemplate - Disable previous date

AndroidMadhu

Active Member
Licensed User
Hello,
I want to disable the date using B4XDateTemplate.
For instance I want to disable the previous dates from Today.

How do I achieve that. Any code reference would be helpful.

Please advice.

Thanks
 

Mahares

Expert
Licensed User
Longtime User
How do I achieve that. Any code reference would be helpful.
I saw a while back a snippet where Erel limits the date to a 10 day range. What I did is modify it so only dates today and forward are accepted. Dates in the past are disallowed.
B4X:
Sub Button1_Click
    Wait For (GetDateTodayOn) Complete (Ticks As Long)
    Log($"Selected date: $Date{Ticks}"$)
End Sub

Private Sub GetDateTodayOn As ResumableSub
    Do While True
        Wait For (dialog.ShowTemplate(DateTemplate, "", "", "Cancel")) Complete (Result As Int)
        Dim zero As Long = 0 
        If Result = xui.DialogResponse_Cancel Then Return zero
        Dim days As Int = DateUtils.PeriodBetweenInDays(DateTime.Now, DateTemplate.Date).Days
        If days < 0 Then
            DateTemplate.Date = DateTime.Now
            Wait For (dialog.Show("Invalid date", "Ok", "", "")) Complete (Result As Int)
        Else
            Return DateTemplate.Date
        End If
    Loop
    Return 0
End Sub
 
Upvote 0

AndroidMadhu

Active Member
Licensed User


Thanks @Mahares ... It fixed the issue...



Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…