B4J Question [ABMaterial] ABMRadioGroup on ABMCustomCard and ABMRadioGroup.GetActive() [Solved]

Anser

Well-Known Member
Licensed User
Longtime User
Hi all,

I am using an ABMCustomCard on a page. I am trying to add an ABMRadioGroup as the Card.SetFrontTitleComponent(RadioLdToWhat)

I am facing 2 issues
1. The RadioGroup's SetActive() is not respecting the command ie even if I say RadioGroup.SetActive(0) OR RadioGroup.SetActive(1), there is no default selection displayed
2. I am unable to retrieve the active selection from the RadioGroup via RadioGroup.GetActive()

Here is the image of what I am trying to create


Here is the code.
B4X:
public Sub ConnectPage()
    
    CreateCard

    page.Resume
    
    ' refresh the page
    page.Refresh
    
    ' Tell the browser we finished loading
    page.FinishedLoading
    ' restoring the navigation bar position
    page.RestoreNavigationBarPosition

End Sub


Sub CreateCard

    Dim Card As ABMCustomCard
    Card.Initialize(page,"CardLeadConv","whitetitle")

    Dim RadioLdToWhat As ABMRadioGroup
    RadioLdToWhat.Initialize(page,"RadioLdToWhat","radiodarklabel")
    RadioLdToWhat.Title = "Convertion ratio"
    RadioLdToWhat.AddRadioButtonNoLineBreak("Leads to Cat 1", True)
    RadioLdToWhat.AddRadioButtonNoLineBreak("Leads to Cat 2", True)
    RadioLdToWhat.AddRadioButtonNoLineBreak("Leads to Cat 3", True)
    ' The following SetActive(0) is not making the default selection to "Leads to Cat 1"
    RadioLdToWhat.SetActive(0)

    ' Code to create a Table named TblLeadConv
    ...
    ...

    Card.SetFrontTopComponent(TblLeadConv)
    Card.SetFrontTitleComponent(RadioLdToWhat)
    page.Cell(3,2).AddComponent(Card)

End Sub

Sub RadioLdToWhat_Clicked(Target As String)
    Log("clicked " & Target)
    
    Dim CardLeadConv As ABMCustomCard = page.Component("CardLeadConv")
    Dim RadioLdToWhat As ABMRadioGroup =  CardLeadConv.GetFrontTitleComponent
    ' I tried the following code too, unfortunately no success   
'    Dim RadioLdToWhat As ABMRadioGroup = page.Component("RadioLdToWhat")
    
    ' The GetActive() value is always zero
    Log( "Active is " & RadioLdToWhat.GetActive() )
    
End Sub

Any help will be appreciated
 

alwaysbusy

Expert
Licensed User
Longtime User
I think we can let it work by doing some refreshes:

In CreateCard:
B4X:
    ...
    page.Cell(3,2).AddComponent(Card)
    page.Cell(3,2).Refresh   ' <---------------------------
   
    RadioLdToWhat.SetActive(0)    ' <---------------------------
    RadioLdToWhat.Refresh   ' <---------------------------
End Sub

In RadioLdToWhat_Clicked:
B4X:
    ...
    RadioLdToWhat.Refresh   ' <---------------------------
    Log( "Active is " & RadioLdToWhat.GetActive() )
End Sub

Explanation:
For the SetActive(), this does nothing until the component is added to the page. So we add it to the page, refresh the cell and then set it active (also needs a component refresh to execute the JavaScript).

For the GetActive(), it is a bit more complex. A normal page.Component() does automatically go the the browser and retrieve values as set in the browser. It appears
CardLeadConv.GetFrontTitleComponent does not do that, it just gives you the server (java) component, but without updating the server side with the values currently in the browser.

Luckely, doing a RadioGroup.Refresh does first look at the current status in the browser and updates the server side. So after this refresh, we get the correct value in GetActive

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