B4J Question [BANano]: [SOLVED] How to transverse elements by name and return attributes?

Mashiane

Expert
Licensed User
Longtime User
Hi there

I'm trying to transverse some form elements by name, the example here gets all the inputs by a particular name e.g. category. This returns the two expected elements. In the future i'd like to serialize these without them having to be inside a 'form' tag.

Issues: One of the elements is checked, the returned value is null however, the attribute property returns the right id. Is there a way to solve this?

B4X:
Sub GetMember1 As Boolean
    Dim elID As String = "category"
    Dim el As BANanoElement = BANano.GetElement($"input[name='${elID}']"$)
    Dim els() As BANanoElement = el.Siblings("")
    For Each radio As BANanoElement In els
        Log(radio)
        Log("*** type")
        Log(radio.GetAttr("type"))
        Log("*** checked")
        Log(radio.GetChecked)
        Log("*** id")
        Log(radio.GetAttr("id"))
        Log("*** value")
        Log(radio.GetValue)
        Log("*** checked attr")
        Log(radio.GetAttr("checked"))
    Next

Whilst the elements are read, I cant seem to get some of the attribute values..

transverse.png


Thanks..
 

alwaysbusy

Expert
Licensed User
Longtime User
Impossible to help without:

1. seeing how it is created

2. how the final html tag looks like

3. how the transpiled javascript code looks like

In short, a small project that can replicate the issues. I use these methods all the time without issues so something is particular in your case.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Thanks, I have attached an example..

I see where my issue is now. The .GetElement output is actually 2 found radio items items, this is correct as per depicted by el.Length = 2. Running el.First returns the first element in that search, the correct input element. I saw there is an el.Last method also but what if I had more than 2 elements, how do I loop them and read each? That is where I'm stuck.

B4X:
Dim elID As String = "category"
    Dim el As BANanoElement = BANano.GetElement($"input[name='${elID}']"$)
    Log(el.Length)
    Log(el.First)
    Log(el.Children(""))
    Log(el.siblings(""))

Thanks.
 

Attachments

  • BANanoExplorer.zip
    2 KB · Views: 391
Last edited:
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Upvote 0
Top