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

Discussion in 'B4J Questions' started by Mashiane, Jan 19, 2019.

  1. Mashiane

    Mashiane Expert Licensed 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?

    Code:
    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..
     
    joulongleu likes this.
  2. alwaysbusy

    alwaysbusy Expert Licensed 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.
     
    joulongleu likes this.
  3. Mashiane

    Mashiane Expert Licensed 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.

    Code:
    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.
     

    Attached Files:

    Last edited: Jan 20, 2019
    joulongleu likes this.
  4. alwaysbusy

    alwaysbusy Expert Licensed User

    Mashiane and joulongleu like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice