-1

I want to read value entered in input field of fragment in controller below is my fragment and controller method.

<core:FragmentDefinition xmlns:core="sap.ui.core"
xmlns:form="sap.ui.layout.form"
xmlns:l="sap.ui.layout"
xmlns="sap.m" >
<Dialog
    id="idSettings"
    draggable="true"
    title="{i18n>Settings_Title}" >
    <content>
        <form:SimpleForm
            id="idSettings_Form"
            backgroundDesign="Transparent"
            editable="true" >
            <form:content>
                <Label text="{i18n>Settings_DeliveryStatus}" />
                <Input
                    id="idSettings_storeId" />
            </form:content>
        </form:SimpleForm>
    </content>

    <buttons>
        <Button
            text="SAVE"
            press="onSettingsSaveBtn" />
        <Button
            text="CANCEL"
            press="onSettingsCancelBtn" />
    </buttons>
</Dialog>

I have tried below options but not working.

1) **********************************************************************

var fragmentId = this.getView().createId("webapp.ZSO_ES4.viewFragments.Settings");
var tab = sap.ui.core.Fragment.byId(fragmentId, "idSettings_storeId");

2) **********************************************************************

var user = sap.ui.core.Fragment.byId("webapp.ZSO_ES4.viewFragments.Settings", "idSettings_storeId").getValue();
Cesar Loachamin
  • 2,740
  • 4
  • 25
  • 33
Dev
  • 11
  • 2
  • 4
  • Does this answer your question? [How to Access Elements from XML Fragment by ID](https://stackoverflow.com/questions/39660161/how-to-access-elements-from-xml-fragment-by-id) – Boghyon Hoffmann Jul 13 '21 at 15:07

1 Answers1

1

Your input should have a value property bound to a JSON Model

 <Input value="{json>name}"/>

Then in your controller you need to instantiate this JSON Model

sap.ui.define([
    "sap/ui/model/json/JSONModel",
], function(JSONModel) {
    return sap.ui.controller("INSERT CONTROLLER NAME HERE", {
        onInit: function() {
            var oJSONModel = new JSONModel({
                name: ""
            });
            this.getView().setModel(oJSONModel, "json");
    },

Once that is setup you can access the value using

this.getView().getModel("json").getProperty("/name");

This is known as MVC... I recommend reading up on it.

Ashley
  • 422
  • 6
  • 18