1. #1
    Sencha Premium Member
    Join Date
    Mar 2012
    Posts
    5
    Vote Rating
    0
    doughboy is on a distinguished road

      0  

    Default Unanswered: DomQuery.selectValue fails using xpath GXT 3

    Unanswered: DomQuery.selectValue fails using xpath GXT 3


    I am using this sample: http://www.sencha.com/examples/#Exam...e:formsexample

    I have added some code to query the dom tree :
    Code:
        private final class DomLookupHandler implements SelectHandler {
            @Override
              public void onSelect(SelectEvent event) {
                  String wVal = DomQuery.selectValue("input[id=\"medication-input\"]", RootPanel.get().getElement() );
                  GWT.log(wVal);
              }
        }
    Using Firebug, I can see my

    HTML Code:
    <div class="GFVDMX3GT" style="position: relative; width: 316px;">
      <label style="width:100px;" class="GFVDMX3IT" for="medication-input">M├ędication:</label>
      <div style="padding-left:105px;" class="GFVDMX3FT">
        <div __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true" id="medication" style="width: 211px;">
          <div class="GFVDMX3JX" style="width:211px;">
            <input type="text" class="GFVDMX3IX GFVDMX3DX" style="width:203px;" value="swswsw" id="medication-input">
          </div>
        </div>
      </div>
    <div class="GFVDMX3ET"></div></div>
    I want to get the value of the value attribute for the input element with id=medication-input. I am assuming the dom is present. Can someone tell me how can I retreive the dom element value attribute value? Look at my query in my class DomLookupHandler, I am using DomQuery.selectValue with a xpath string. But my query never returns a value (always null).

    Thanks for any help.

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    This isn't a problem with DomQuery, but with your query - the selectValue method returns the contents of the element or attribute that is selected by the query. In your case, it will try to return the contents of an input tag, which is always empty.

    Instead, you want to select the value, something like this:

    Code:
    DomQuery.selectValue(queryToElement + "/@value", parent)
    or in Java
    Code:
    ((InputElement)DomQuery.selectNode(queryToElement, parent)).getValue()
    Additionally, when selecting by ID, there is no need to use the id attribute, as DomQuery supports most CSS selectors - you could instead say just
    Code:
    DomQuery.selectValue("#medication-input/@value")
    There is no need for a parent, since ID attributes in HTML must be unique across the document, and the browser has built in mechanisms to search for an element by a specific ID.

Thread Participants: 1