Skip to Content
0

Fragment dialog with input field with value help that open select dialog ..

Oct 20, 2016 at 12:53 PM

1.4k

avatar image

Hello colleagues developers,

I have a problem with catching Event from Select dialog confirm event or when choose an item from list. First, on main screen when button is pressed, dialog made as fragment but with controller is opened and there are some input fields and on one of them I need value help or search help and I manage to open a second dialog which is also fragment and Select dialog and when I choose an item the event on confirm which is implemented in first dialog controller does not fire.

Maybe there is a better way to accomplish such a scenario or maybe I just missed something trivial.

If don't understand I can post code and screenshots..

Thanks

Code:

AddMaterial.fragment.xml

<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:l="sap.ui.layout" >
<Dialog
id="addMaterialFragment"
title="{i18n>AddNewMaterial}"
icon="sap-icon://add-product"
stretchOnPhone="true"

showHeader="true" >
<content>
<FlexBox

direction="Column"
fitContainer="true"
alignItems="Left"
justifyContent="Left">
<items>
<Label
id="materialLabel"
text="{i18n>MaterialLabelDialog}" labelFor="materialInput" design="Bold" />
<Input
id="materialInput"
type="Text"
value=''
width="175px"
maxLength="18" />
<Input
id="materialTextInput"
type="Text"
value=''
placeholder="{i18n>MaterialPlaceholder}"
showValueHelp="true"
valueHelpRequest="handleMaterialTextValueHelp"
width="300px"
maxLength="50"
submit="onMaterialTextSubmit" />
<Label
id="plannedLabel"
text="{i18n>PlannedAmountLabel}" labelFor="plannedInput" design="Bold" />
<Input
id="plannedInput"
type="Text"
value=''
width="120px"
maxLength="18" />
</items>
</FlexBox>
</content>
<buttons>
<Button
id="btnCloseMat"
text="{i18n>CancelButton}"
press="closeDialog"
width="120px"/>
<Button
id="btnAddMaterial"
text="{i18n>MaterialDialogSaveBtn}"
press="saveMaterial"
width="120px"
type="Accept" />
</buttons>
</Dialog>
</core:FragmentDefinition>

AddMaterial.controller.js

jQuery.sap.require("jquery.sap.resources");
jQuery.sap.require("zaga.workorder.dialog.MySelectDialog");
jQuery.sap.declare("zaga.workorder.dialog.AddMaterial");

sap.ui.controller("zaga.workorder.dialog.AddMaterial", {

closeDialog: function(evt) {
sap.ui.getCore().byId("addMaterialFragment").destroy();
},

onExit: function() {
sap.ui.getCore().byId("addMaterialFragment").destroy();
},


// Material search help
handleMaterialTextValueHelp: function (oEvent) {
var that = sap.ui.getCore().byId("addMaterialFragment");

// read texts from i18n model
var oBundle = jQuery.sap.resources({url: "i18n/i18n.properties"});

var user = oBundle.getText("GatewayUsername");
var pass = oBundle.getText("GatewayPassword");

// Using OData model to connect against a real service
var url = "proxy/https/... ";
oModel = new sap.ui.model.odata.ODataModel(url, false, user, pass);
sap.ui.getCore().setModel(oModel);

var maktg = sap.ui.getCore().byId("materialTextInput").getValue();
if(maktg == "") {
// Unesite deo naziva materijala
sap.m.MessageToast.show(oBundle.getText("EnterMaterialNamePart"));
return;
}

var sInputValue = oEvent.getSource().getValue();

that.inputId = oEvent.getSource().getId();
// create value help dialog
if (!that._materialValueHelpDialog) {
that._materialValueHelpDialog = sap.ui.xmlfragment(
"zaga.workorder.dialog.MaterialSH",
that
);
that.addDependent(that._materialValueHelpDialog);
}

// create a filter for the binding
var FilterOperator = sap.ui.model.FilterOperator;
that._materialValueHelpDialog.getBinding("items").filter([
new sap.ui.model.Filter("Maktg", FilterOperator.EQ, maktg)
]);
// open value help dialog filtered by the input value
that._materialValueHelpDialog.open(sInputValue);

},

handleMatValueHelpClose: function(oEvent) {

var oSelectedItem = oEvent.getParameter("selectedItem");
console.log(oSelectedItem);
if (oSelectedItem) {
var materialInput = sap.ui.getCore().byId("materialInput");
materialInput.setValue(oSelectedItem.getTooltip());
var materialText = sap.ui.getCore().byId("materialTextInput");
materialText.setValue(oSelectedItem.getTitle());
}
oEvent.getSource().getBinding("items").filter([]);
},

});

MaterialSH.fragment.xml

<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:zagawo="zaga.workorder.dialog" >
<zagawo:MySelectDialog
title="{i18n>MaterialSearchHelpTitle}"

items="{/EtMaterialsSet}"
noDataText="{i18n>SearchHelpNoData}"
confirm="handleMatValueHelpClose"
cancel="handleMatValueHelpClose">
<StandardListItem
title="{Maktg}"
info="{Matnr}"
tooltip="{Matnr}" />
</zagawo:MySelectDialog>
</core:FragmentDefinition>

10 |10000 characters needed characters left characters exceeded

understand, but still cannot help if no code

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Jun Wu Oct 22, 2016 at 06:47 PM
1

if (!that._materialValueHelpDialog) {
that._materialValueHelpDialog = sap.ui.xmlfragment(
"zaga.workorder.dialog.MaterialSH",
that
);
that.addDependent(that._materialValueHelpDialog);
}

change to

if (!that._materialValueHelpDialog) {
that._materialValueHelpDialog = sap.ui.xmlfragment(
"zaga.workorder.dialog.MaterialSH",
this
);
that.addDependent(that._materialValueHelpDialog);
}

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Wow, congratulations!

I thought that tried everything..

Just one more thing. How can I call a function in parent view/page controller from dialogs controller?

I need to submit data from dialog and to call a web service to save data and update model and list in parent view/page.

0
Jun Wu Oct 24, 2016 at 12:20 PM
1

you can use event to inform the parent controller

google ui5 eventbus

Share
10 |10000 characters needed characters left characters exceeded
Vladimir Erakovic Oct 24, 2016 at 01:17 PM
0

Ok thanks,

I made it somehow..

Here on new SCN there isn't Correct Answer button, just Accept. Is that the same?

Did you get some points?

Show 1 Share
10 |10000 characters needed characters left characters exceeded

not sure how to track it in new scn, but I believe I got it:)

0