B4J Question ABMDateTimePicker MinimumDate does not set correctly

Rob White

Member
Licensed User
Hi all,
I have two ABMDatePickers on a page which are supposed to set up the start and finish date/times for an event here is the whole page code for my test program
B4X:
'Class module
Sub Class_Globals
    Private ws As WebSocket 'ignore
    ' will hold our page information
    Public page As ABMPage
    ' page theme
    Private theme As ABMTheme
    ' to access the constants
    Private ABM As ABMaterial 'ignore   
    ' name of the page, must be the same as the class name (case sensitive!)
    Public Name As String = "TstDTP"  '<-------------------------------------------------------- IMPORTANT
    ' will hold the unique browsers window id
    Private ABMPageId As String = ""
    ' your own variables   
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ' build the local structure IMPORTANT!
    BuildPage       
End Sub

#Region ABM
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)   
    Log("Connected")
        
    ws = WebSocket1       
    
    ABMPageId = ABM.GetPageID(page, Name,ws)
    
    Dim session As HttpSession = ABM.GetSession(ws, ABMShared.SessionMaxInactiveIntervalSeconds)
    If session.IsNew Then
        session.Invalidate
        ABMShared.NavigateToPage(ws, "", "./")
        Return
    End If
        
    If ABMShared.NeedsAuthorization Then
        If session.GetAttribute2("IsAuthorized", "") = "" Then
            ABMShared.NavigateToPage(ws, ABMPageId, "../")
            Return
        End If
    End If       
    ABM.UpdateFromCache(Me, ABMShared.CachedPages, ABMPageId, ws)       
    If page.ComesFromPageCache Then
        ' when we have a page that is cached it doesn't matter if it comes or not from a new connection we serve the cached version.
        Log("Comes from cache")       
        page.Refresh       
        page.FinishedLoading       
    Else
        If page.WebsocketReconnected Then
            Log("Websocket reconnected")
            ' when we have a client that doesn't have the page in cache and it's websocket reconnected and also it's session is new - basically when the client had internet problems and it's session (and also cache) expired before he reconnected so the user has content in the browser but we don't have any on the server. So we need to reload the page.
            ' when a client that doesn't have the page in cache and it's websocket reconnected but it's session is not new - when the client had internet problems and when he reconnected it's session was valid but he had no cache for this page we need to reload the page as the user browser has content, reconnected but we have no content in cache
            ABMShared.NavigateToPage (ws, ABMPageId, "./" & page.PageHTMLName)
        Else
            ' when the client did not reconnected it doesn't matter if the session was new or not because this is the websockets first connection so no dynamic content in the browser ... we are going to serve the dynamic content...
            Log("Websocket first connection")
            page.Prepare
            ConnectPage           
        End If
    End If
    Log(ABMPageId)       
End Sub

Private Sub WebSocket_Disconnected
    Log("Disconnected")
End Sub

Sub Page_ParseEvent(Params As Map)
    Dim eventName As String = Params.Get("eventname")
    Dim eventParams() As String = Regex.Split(",",Params.Get("eventparams"))
    
    #If DEBUG
    Log($"Evt fired --->${eventName} Number params = ${Params.Size}"$)
    For i = 0 To Params.Size-1
        Log($"    Key = ${Params.GetKeyAt(i)}, value = ${Params.GetValueAt(i)}"$)
    Next
    Log("-----------------------------------------------------")
    #End if
        
    If eventName = "beforeunload" Then
        Log("preparing for url refresh")
        ABM.RemoveMeFromCache(ABMShared.CachedPages, ABMPageId)
        Return
    End If
    Dim caller As Object = page.GetEventHandler(Me, eventName)
    If caller = Me Then
        If SubExists(Me, eventName) Then
            Params.Remove("eventname")
            Params.Remove("eventparams")
            If eventName = "page_dropped" Then
                page.ProcessDroppedEvent(Params)
            End If
            Select Case Params.Size
                Case 0
                    CallSub(Me, eventName)
                Case 1
                    CallSub2(Me, eventName, Params.Get(eventParams(0)))
                Case 2
                    If Params.get(eventParams(0)) = "abmistable" Then
                        Dim PassedTables As List = ABM.ProcessTablesFromTargetName(Params.get(eventParams(1)))
                        CallSub2(Me, eventName, PassedTables)
                    Else
                        CallSub3(Me, eventName, Params.Get(eventParams(0)), Params.Get(eventParams(1)))
                    End If
                Case Else
                    ' cannot be called directly, to many param
                    CallSub2(Me, eventName, Params)
            End Select
        End If
    Else
        CallSubDelayed2(caller, "ParseEvent", Params) 'ignore
    End If
End Sub

public Sub BuildTheme()
    ' start with the base theme defined in ABMShared
    theme.Initialize("pagetheme")
    theme.AddABMTheme(ABMShared.MyTheme)

    ' add your specific page themes
    
End Sub

public Sub BuildPage()
    ' initialize the theme
    BuildTheme
    
    ' initialize this page using our theme
    page.InitializeWithTheme(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, theme)
    page.ShowLoader=True
    page.PageHTMLName = "index.html"
    page.PageTitle = "Template"
    page.PageDescription = "Template"
    page.PageKeywords = ""
    page.PageSiteMapPriority = ""
    page.PageSiteMapFrequency = ABM.SITEMAP_FREQ_YEARLY
        
    page.ShowConnectedIndicator = True
                
#Region NOT SAVED: 2021-07-06T12:18:42
    'PHONE
    '╔═══════════════════════════════════════════════════════════════════════════════════╗
    '║ 1,1                                                   | 1,2         |             ║
    '╚═══════════════════════════════════════════════════════════════════════════════════╝

    'TABLET
    '╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════╗
    '║ 1,1                                                                   | 1,2             |                 ║
    '╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════╝

    'DESKTOP
    '╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╗
    '║ 1,1                                                  |          | 1,2                                                  |          ║
    '╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╝

    page.AddRows(1,True,"").AddCellsOS(1,0,0,0,8,8,5,"").AddCellsOS(1,0,0,1,2,2,5,"")
    page.BuildGrid ' IMPORTANT!
#End Region
End Sub

public Sub ConnectPage()           
    '    connecting the navigation bar
    ' ABMShared.ConnectNavigationBar(page)
    
    Dim dtpStart As ABMDateTimePicker
    dtpStart.Initialize(page,"dtpS",ABM.DATETIMEPICKER_TYPE_DATETIME,DateTime.Now,"Start date/Time","mytheme")
    dtpStart.Tag = "StartDate"
    dtpStart.ReturnDateFormat="DD MMM YY"
    dtpStart.ReturnTimeFormat="hh:mm"
    dtpStart.PickText="Next"
    dtpStart.ClearText = ""
    page.Cell(1,1).AddComponent(dtpStart)

    Dim dtpEnd As ABMDateTimePicker
    dtpEnd.Initialize(page,"dtpE",ABM.DATETIMEPICKER_TYPE_DATETIME,dtpStart.GetDate+(45/25)* DateTime.TicksPerHour,"End date/Time","mytheme")
    dtpEnd.Tag = "EndDate"
    dtpEnd.ReturnDateFormat="DD MMM YY"
    dtpEnd.ReturnTimeFormat="hh:mm"
    dtpEnd.PickText="Next"
    dtpEnd.ClearText = ""
    dtpEnd.MinimumDate = dtpStart.GetDate
    page.Cell(1,2).AddComponent(dtpEnd)

    ' refresh the page
    page.Refresh
    
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition   
End Sub
#end region

Sub dtps_changed(Target As String,DMSstr As String)        ' DMS - dateMilliSeconds
    Try
        Dim DMS As Long = DMSstr
        Dim E As ABMDateTimePicker = page.Component("dtpE")
        E.MinimumDate = DMS
        Dim A As Long = 45            ' This is temp for paddock area (ha). 25 below is estimated ha's per hour.
        E.SetDate(DMS + (A/25)* DateTime.TicksPerHour)
        E.Refresh
        
    Catch
        Log("Error in dtps_changed "&LastException)
    End Try
End Sub


#Region ABMPage
' clicked on the navigation bar
Sub Page_NavigationbarClicked(Action As String, Value As String)
    ' saving the navigation bar position
    page.SaveNavigationBarPosition
    If Action = "LogOff" Then
        ABMShared.LogOff(page)
        Return
    End If

    ABMShared.NavigateToPage(ws, ABMPageId, Value)
End Sub

Sub Page_DebugConsole(message As String)
    Log("---> " & message)
End Sub
#end region

Note the code in dpts_changed sets the minimumDate of dptE to the starting time/date plus an offset BUT
when you click on dtpE the minimum is not being reset but the date/time is changed correctly.

Bug or my problem?
 

MichalK73

Well-Known Member
Licensed User
Longtime User
I tested your code.
The fact is there is some bug in ABMaterial.
I solved like this:

B4X:
Sub dtps_changed(Target As String,DMSstr As String)        ' DMS - dateMilliSeconds
    Try
        Dim DMS As Long = DMSstr
'        Dim E As ABMDateTimePicker = page.Component("dtpE")
'        E.MinimumDate = DMSstr
'        Dim A As Long = 45            ' This is temp for paddock area (ha). 25 below is estimated ha's per hour.
''        E.SetDate(DMS + (A/25)* DateTime.TicksPerHour)
'        E.SetDateISO(DateTime.Date(DMS + (A/25)* DateTime.TicksPerHour))
'
'        E.Refresh

        
        Dim dtpEnd As ABMDateTimePicker
        dtpEnd.Initialize(page,"dtpE",ABM.DATETIMEPICKER_TYPE_DATETIME,DMS+(45/25)* DateTime.TicksPerHour,"End date/Time","mytheme")
        dtpEnd.Tag = "EndDate"
        dtpEnd.ReturnDateFormat="DD MMM YY"
        dtpEnd.ReturnTimeFormat="hh:mm"
        dtpEnd.PickText="Next"
        dtpEnd.ClearText = ""
        dtpEnd.MinimumDate = DMS
        page.Cell(1,2).RemoveAllComponents
        page.Cell(1,2).AddComponent(dtpEnd)
        page.Refresh
    Catch
        Log("Error in dtps_changed "&LastException)
    End Try
End Sub
 
Upvote 0
Top