cancel
Showing results for 
Search instead for 
Did you mean: 

Pass data from Dialog to Calling Screen without "nav" "to"

dhrubajyoti_rakshit2
Participant
0 Kudos

Scenario: a dialog has 1 Input field and a Submit button. On pressing a Submit Button in the value from the Input field should pass to the View from which dialog is called.

1. Should I use Eventbus or there is some other way.

2. Can I pass the ID of the Submit button as well to the calling screen

-Regards

Dhrubajyoti

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi rakshit,

               Why would you open a dialog in a different view or are you using fragments, in case you are using fragments you could just give the input field a id and retreive using fragment.byId and then get the value. If you are still want to open the dialog in a different view you could just use the eventbus that's the simplest way to pass data between views.

Regards,

              Pruthvi.    

dhrubajyoti_rakshit2
Participant
0 Kudos

Hi Pruthvi,

I tried the EventBus with below code

For sending data:

       var oEventBus = sap.ui.getCore().getEventBus();
      
oEventBus.publish({
      
data: {context : "username"}
      
});

For receiving
sap.ui.getCore().getEventBus().data.context

Am I doing it correct?

Former Member
0 Kudos

Hi Rakshit,

Subscribe to the event channel in the view's controller that you need the data in

                  sap.ui.getCore().getEventBus().subscribe("show", "username", eventHandler, this);

in the eventHandler function

eventHandler  = function (channelId, eventId, data) {

                    if (eventId === "username") {

             alert(data.context); // data recieved in the data object will contain username that you passed.

                    } else {

                              jQuery.sap.log.error("'nav' event cannot be processed. There's no handler registered for event with id: " + eventId);

                    }

          };

Send Data by publishing the event from the dialog view / controller.

var oEventBus = sap.ui.getCore().getEventBus();
oEventBus.publish("show","username",{


data: {context : "username"}


});

Regards,

                  Pruthvi.



Answers (0)