Search code examples
javascriptxmlsapui5

get value from fragment input SAPUI5


I'm trying to get value from input and put it into my variable in controller but all the time it returns " Unable to get property 'getValue' of undefined or null reference ". How should i do that?

My popover fragment:

<core:FragmentDefinition 
xmlns="sap.m" 
xmlns:core="sap.ui.core">
<Popover showHeader="false" contentWidth="240px" contentHeight="350px" placement="Top">
    <NavContainer id="navConImage">
        <Page id="reserve" showNavButton="true" navButtonPress="onPopNavBack" title="Reserve">
            <Input placeholder="data" id="userData"/>
            <Button type="Accept" text="Accept" press="onAcceptRoomReservation">
                        <layoutData>
                            <OverflowToolbarLayoutData moveToOverflow="false" />
                        </layoutData>
                    </Button>
        </Page>
    </NavContainer>
</Popover>

my controller:

onAcceptRoomReservation: function(oEvent) {

        var user = this.getView().byId("userData").getValue();
        console.log(tab);
    },

Solution

  • The way i solved it was:

    var user = sap.ui.core.Fragment.byId("idOfNavContainer", "userData").getValue();