B4J Question [ABMaterial]: SOLVED - How to clear ABMDateTimePicker via code?

Harris

Expert
Licensed User
Longtime User
Dim cstart As ABMDateTimePicker = inp.Content.Component("docpost")
cstart.SetDateISO( DateTime.Date(DateTime.Now))


This is an issue which needs some clarification.
When using cstart.SetDate (date as long), even when getting the long form a field in your table, it reverts to the last date / time that was used in this form.

SetDateISO( date as string)

However, when using SetDateISO ( the retrieved date as string ), the control will set your date properly.

Use 0 instead of null for a begin date if need be...
If cstart = 0 then
force to set a d ate
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
I noted this too before and what i ended up doing was to re-create the component each time between my cycle of CRUD as I also didnt understand what was happening. I spent many hours trying to identify the problem and finally gave up and did this "fix". This should really have an option to initialize it without a date/clear the date.

B4X:
Sub msdocSetContents(pMap As Map)
    Dim msdoc As ABMModalSheet
    msdoc = page.ModalSheet("msdoc")
    'Remove the component from the modal sheet
    msdoc.Content.Cell(4,1).RemoveComponent("dpdocdocumentdate")
    'Add the component to the modalsheet
    Dim dpdocdocumentdate As ABMDateTimePicker
    Dim dpdocdocumentdateDate As Long = DateTime.Now
    dpdocdocumentdate.Initialize(page, "dpdocdocumentdate", ABM.DATETIMEPICKER_TYPE_DATE, dpdocdocumentdateDate, "Document Date", "dp")
    dpdocdocumentdate.WeekText = "Week"
    dpdocdocumentdate.TodayText = "Today"
    dpdocdocumentdate.ReturnDateFormat = "YYYY-MM-DD"
    dpdocdocumentdate.ReturnTimeFormat = ""
    dpdocdocumentdate.Language = "en"
    dpdocdocumentdate.FirstDayOfWeek = ABM.FIRSTDAYOFWEEK_SUNDAY
    dpdocdocumentdate.PickText = "OK"
    dpdocdocumentdate.CancelText = "Back"
    msdoc.Content.Cell(4,1).AddComponent(dpdocdocumentdate)
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
After much thought, I dediced to try clearing it via jquery...

B4X:
public Sub SetValue(page As ABMPage, id As String, value As String)
    Try
        id = id.tolowercase
        Dim jqe As JQueryElement = page.ws.GetElementById(id)
        jqe.SetVal(value)
    Catch
    End Try
End Sub

And using it like...

B4X:
'use jquery to clear
    ABMShared.SetValue(page,dpdocdocumentdate.id,"")
    ABMShared.SetValue(page,dpdocdatereceived.id,"")
    ABMShared.SetValue(page,dpdocrespondby.id,"")
    ABMShared.SetValue(page,dpdocdateresponded.id,"")
 
Upvote 0

Harris

Expert
Licensed User
Longtime User

Ah yes, there are times when you need to remove the component at a row(s) in order to re-init them (add / edit).
Trying to update some properties just does not work.

When I find that something isn't behaving, I remove the row and re-init it. Build form seems to control all and respects (many) adjustments made when editing, or adding new.

The ABM.DATETIMEPICKER_TYPE_DATE type will show date and time as opposed to just a Date.

This is very infrequent but sometimes, it is the only thing that works. I can't imagine the complexity behind the scenes.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…