Based on condition, i want to remove one of the element(highlighted in the img) from Custom List. Here is the code i did.Is it the right way of doing?
If i pass null to the formatter, as Avatar icon by default it shows one and the icon should not be displayed for null value.
View::`
<VBox>
<List id="sonarRepId" items="{ path: 'sonarMetrics>/measures' }" updateFinished="onUpdateListFinished">
<items>
<CustomListItem id="idSonarList">
<FlexBox id="idFlex" alignItems="Start" justifyContent="SpaceBetween" class="sapUiSmallMarginBeginEnd" height="88px">
<items>
<VBox class="sapUiSmallMarginTop">
<Link text="{sonarMetrics>value}" press="handlePress" class="sonarsapMLnk"/>
<HBox class="sapUiSmallMarginTopBottom">
<core:Icon size="2rem" class="sonarsapMObjLIcon" src="{sonarMetrics>imageL}"/>
<Label text="{sonarMetrics>name}" class="sapUiTinyMarginBegin"/>
</HBox>
<layoutData>
<FlexItemData growFactor="2"/>
</layoutData>
</VBox>
<HBox id="idHbox" class="sapUiSmallMarginTop">
<items>
<HBox class="sapUiSmallMarginTop">
<Link id="idLinkState" text="{sonarMetrics>state}" press="stateHandlePress" class="sapUiTinyMarginEnd"/>
<Avatar id="idAvatar" initials="{parts : [ 'sonarMetrics>state_value'], formatter: '.formatter.formatNumeric'}" displaySize="XS"
backgroundColor="{parts : [ 'sonarMetrics>state_value'], formatter: '.formatter.formatIconColor'}"/>
</HBox>
</items>
</HBox>
</items>
</FlexBox>
</CustomListItem>
</items>
</List>
</VBox>
Controller
onUpdateListFinished: function (oEvent) {
// var sonarList = this.getView().byId("sonarRepId");
// var items = sonarList.getItems();
// for (var i = 0; i < items.length; i++) {
// var oAvatarIcon = oEvent.getSource().getItems()[i].mAggregations.content[0].mAggregations.items[1].mAggregations.items[0].mAggregations.items[1];
// if(oAvatarIcon){
// var delItemColor = oAvatarIcon.getProperty("backgroundColor");
// if (delItemColor === "Accent10") {
// oAvatarIcon.destroy();
// }
// }
// }
}
Hide the Avatar control instead of destroying it. You can use Expression Binding for this.
Expression Binding:
visible="{= ${sonarMetrics>state_value} !== null}"
The Avatar control:
<Avatar id="idAvatar" visible="{= ${sonarMetrics>state_value} !== null}"
initials="{parts : [ 'sonarMetrics>state_value'], formatter: '.formatter.formatNumeric'}"
displaySize="XS" backgroundColor="{parts : [ 'sonarMetrics>state_value'], formatter: '.formatter.formatIconColor'}"/>
alexP mentioned of ExpressionBinding which is accurate.
I would like to suggest that the below way of handling is more effective and handles more test cases.
visible="{= !!${sonarMetrics>state_value}}"
Related
I have been working on dialog in fragment , for a sample :
test.fragment.xml :
<core:FragmentDefinition
xmlns="sap.m"
xmlns:f="sap.ui.layout.form"
xmlns:core="sap.ui.core">
<Dialog title="P Selection" id='TestDialog1'>
<content>
<f:SimpleForm id="SimpleFormDisplay354"
minWidth="1024"
maxContainerCols="2"
editable="false"
layout="ResponsiveGridLayout"
title=""
labelSpanL="3"
labelSpanM="3"
emptySpanL="4"
emptySpanM="4"
columnsL="1"
columnsM="1">
<f:content>
<Label text="DC" />
<Select id='Test1DCId'
forceSelection="false"
items="{
path: '/P/DC',
sorter: { path: 'Name' }
}">
<core:Item key="{key}" text="{value}" />
</Select>
<Label text="Quantity" />
<Select id='Test1Quantity'
forceSelection="false"
items="{
path: '/P/Quantity',
sorter: { path: 'Name' }
}">
<core:Item key="{key}" text="{value}" />
</Select>
</f:content>
</f:SimpleForm>
</content>
<buttons>
<Button text="OK" press="onTest1OkButtonPress" />
</buttons>
<buttons>
<Button text="Cancel" press="onTest1CancelButtonPress" />
</buttons>
</Dialog>
</core:FragmentDefinition>
In test.view.xml:
The view part when I want to open a dialog is as:
<m:Select id="Gu" items="{/Gu/GList}" change="onTestPress">
<c:Item key="{key}" text="{value}" />
<m:layoutData>
<l:GridData span="L2 M2 S2"/>
</m:layoutData>
</m:Select>
In test.Controller.js:
onTestPress: function () {
this.ADD = 'Yes';
if (!this.byId("TestDialog1")) {
this._oDialog = sap.ui.xmlfragment("test", this);
this.getView().addDependent(this._oDialog);
}
this._oDialog.open();
},
here in similar way may I how can I use multiple dialogs in the same fragment ? Is this possible ?
I have tried as giving another dialog with different ID TestDialog2 ,
And in view some test button and on press , i need to open a Dialog and i tried as:
onTestButtonPress: function () {
this.ADD = 'Yes';
if (!this.byId("TestDialog2")) {
this._oDialog1 = sap.ui.xmlfragment("test1", this);
this.getView().addDependent(this._oDialog1);
}
this._oDialog1.open();
},
But this doesn't work as expected also Throws error Error: Error: adding element with duplicate id.....
I have searched Doc's and many examples but i have been stuck finding an example which shows this use case......
Any help or a sample or a guiding link is much appreciated , TIA
i have a big trouble that's freaking me out, check it out:
This is my xml for a View, program is divided in two differents Views, first of them, a table with navigation and second one is the details, involved in a form.
<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="Hello_World.Hello_World.controller.View2"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:form="sap.ui.layout.form">
<App>
<pages>
<Page title="Detalles" showHeader="true">
<Button type="Back" press="patras" tooltip="test"/>
<VBox>
</VBox>
<form:SimpleForm id="formPruebas" maxContainerCols="2" layout="ResponsiveGridLayout" labelSpanL="5" labelSpanM="4" labelSpanS="6" title="Formulario">
<Label text="CustomerID"/>
<Text text="{jsonmodel>CustomerID}"/>
<Label text="CompanyName"/>
<Text text="{CompanyName}"/>
<Label text="ContactTitle" />
<Text text="{ContactTitle}"/>
<Label text="Adress"/>
<Text text="{Adress}"/>
<Label text="City"/>
<Text text="{City}"/>
<Label text="PostalCode"/>
<Text text="{PostalCode}"/>
<Label text="Country" />
<Text text="{i18n>Country}"/>
<Button text="Aceptar" type="Accept">
<layoutData>
<FlexItemData growFactor="1" />
</layoutData>
</Button>
<Button text="Editar" width="100px">
<layoutData>
<FlexItemData growFactor="1" />
</layoutData>
</Button>
</form:SimpleForm>
</Page>
</pages>
</App>
Alright so this is my controller:
onInit: function() {
var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
oRouter.getRoute("View2").attachMatched(this._onRouteMatched, this);
},
_onRouteMatched: function(oEvent) {
var idDevuelto = oEvent.getParameter("arguments").data;
var idCompleto = "/Customers('" + idDevuelto + "')";
//var oForm = this.getView().byId("formPruebas");
var oForm = this.getView().byId("formPruebas");
var serviceUrl = "myurl";
var oModelData = new sap.ui.model.odata.ODataModel(serviceUrl,{
JSON:true,
useBatch: false
});
oModelData.read(idCompleto, {
success: function (oData) {
sap.m.MessageToast.show(oData.CustomerID);
var oModel = new JSONModel(oData.results);
oForm.setModel(oModel.results);
},
error: function (oError) {
sap.m.MessageToast.show("No funca");
}
});
},
However the result is not showing on my view when i run the program, any idea?
PD: I'm pretty noob on sapui5
Finally i found the solution of the problem, if you check the XML code at the beginning of the question , you realize there is not path in Form element.
In mi first view i have a table with id and a PATH which i don't have in the Form so the fastest way i solve it is to put in the XML a slash, an example:
<form:SimpleForm id="formPruebas" maxContainerCols="2" layout="ResponsiveGridLayout" labelSpanL="5" labelSpanM="4" labelSpanS="6" title="Formulario">
<Label text="CustomerID"/>
<Text text="{/CustomerID}"/> // the slash i mean
With that fix, i only do oForm.setModel(oModel) so everything is connected and works
fine, i want to share this information if more people deal with the same error as i did.
Thanks all ideas.
I'm creating a read only form that will be used to display a summary of information. I need to send a parameter to the backend first before getting the information but I don't seem to see that parameter is reaching it.
It does reach the entity set but it does not show the parameter. Am I binding correctly?
This is on the controller:
onInit: function() {
var urlEnding = "1000012233";
var oFilterDist = new sap.ui.model.Filter("ID",
sap.ui.model.FilterOperator.EQ, urlEnding);
var summaryText = this.getView().byId("summaryForm");
summaryText.bindElement({
path: "/SummaryScreenSet",
filters: [oFilterDist]
});
}
This is on the View
<VBox class="sapUiSmallMargin" fitContainer="true"
height="100%" width="100%" justifyContent="End"
displayInline="true" id="leftVBox" items="{/SummaryScreenSet}">
<items>
<f:SimpleForm editable="true" layout="ResponsiveGridLayout" id="summaryForm" columnsL="1" columnsXL="1" labelSpanL="5" title="Account Summary" labelSpanM="5">
<f:content>
<Label text="Status" id="__label6" design="Bold" class="sizeText"/>
<ObjectStatus text="{CONTRACT_STATUS}" id="__status6" state="Success" class="boldText"/>
<Label text="Permit Required" id="__label10" design="Bold" class="sizeText"/>
<Text text="{PERMIT_REQD}" id="__text32" wrapping="false" class="sizeText"/>
<Label text="Bill Date | Due Date" id="__label11" design="Bold" class="sizeText"/>
<Text text="{BILL_DATE} | {DUE_DATE}" id="__text33" wrapping="false" class="sizeText"/>
<Label text="Last Estimated Date | Next MR Date" id="__label17" design="Bold" class="sizeText"/>
<Text text="{LAST_PAYMENT_DATE} | {nextMRDate}" id="__text39" wrapping="false" class="sizeText"/>
</f:content>
</f:SimpleForm>
</items>
</VBox>
Going to assume you want a single, specific entry. In that case, what you're looking for is the Entity, not the EntitySet + filter. Coincidentally, here's one I wrote yesterday that works. I've changed the paths and ID's to reflect yours:
var form = this.getView().byId('summaryForm');
form.bindElement({
path: "/SummaryScreenSet('" + urlEnding + "')",
events: {
change: function() {
//triggers on error too I think
form.setBusy(false);
},
dataRequested: function() {
form.setBusy(true);
}
}
});
In that case you don't need the VBOX either, just the form. Don't forget to implement SUMMARYSCREEN_GET_ENTITY or whatever the method is on your DPC_EXT.
Edit: might want to set editable on the form to false, it shrinks the layout to suit text instead of inputs.
View1.view.xml
<mvc:View xmlns:f="sap.ui.layout.form" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="Login.controller.View1">
<App>
<pages>
<Page title="Login">
<f:SimpleForm maxContainerCols="2" editable="true" layout="ResponsiveGridLayout" labelSpanL="4" labelSpanM="4" emptySpanL="0" emptySpanM="0" columnsL="2" columnsM="2">
<f:content>
<Input width="100%" id="__input0" placeholder="UserID" liveChange="true" />
<Input width="100%" id="__input1" type="Password" placeholder="Password" />
<Button text="Login" width="100px" id="__button0" type="Accept" press="Validation" />
</f:content>
</f:SimpleForm>
<Table items="{ path: '/Item' }" id="tableID" width="90%">
<items>
<ColumnListItem counter="0" id="__item0">
<cells>
<Text id="a1" text="{OrderID}" />
<Text text="{Quantity}" />
</cells>
</ColumnListItem>
</items>
<columns>
<Column id="__column0">
<header>
<Label text="OrderID" id="__label0" />
</header>
</Column>
<Column id="__column1">
<header>
<Label text="Quantity" id="__label1" />
</header>
</Column>
</columns>
</Table>
<content/>
</Page>
</pages>
</App>
</mvc:View>
view1.controller.js
sap.ui.define(["sap/m/MessageToast",
"sap/ui/core/mvc/Controller", 'sap/ui/model/json/JSONModel'
], function(MessageToast, Controller, JSONModel) {
"use strict";
return Controller.extend("Login.controller.View1", {
onInit: function(oEvent) {
// set explored app's demo model on this sample
var oModel = new JSONModel(jQuery.sap.getModulePath("Login", "/model/Products.json"));
sap.ui.getCore().setModel(oModel);
this.getView().byId("tableID").setModel(oModel);
// this.getView().byId("samplepie").setModel(oModel);
},
Validation: function() {
var UserID = this.getView().byId("__input0").getValue();
var Password = this.getView().byId("__input1").getValue();
if (UserID == "") {
MessageToast.show("Please Enter UserID");
return false;
} else if (Password == "") {
MessageToast.show("Please Enter Password");
return false;
} else if (UserID == sap.ui.getCore().byId("a1").getValue()) {
MessageToast.show("authenticated ");
}
}
});
});
products.json
{
"Item": [{
"OrderID": "1100M",
"Quantity": 100
}, {
"OrderID": "11001I",
"Quantity": 250
},
{
"OrderID": "11002D",
"Quantity": 400
}
]
}
I have tried this code for login along with authentication but am getting error as getValue not defined when i used to fetch JSON values from view to controller,can anyone please give a solution?
Is there a possibilty of using a NavContainer inside a sap.m.Dialog fragment. In PopOver it is possible to have it done but when trying with Dialog nothing is rendered inside the dialog .
Here is the code :
<core:FragmentDefinition xmlns:core="sap.ui.core"
xmlns:layout="sap.ui.layout" xmlns="sap.m">
<Dialog title="Customer Search" type="Message">
<NavContainer id="navCon">
<Page id="master" title="Search ">
<Label text="Customer Name"></Label>
<Input></Input>
<Label text="Payer Code"></Label>
<Input></Input>
<Label text="Customer City"></Label>
<Input></Input>
<Label text="Customer Postal Code"></Label>
<Input></Input>
<Label text="SBU" />
<layout:ResponsiveFlowLayout>
<RadioButton groupName="supplierCaused" text="Yes" />
<RadioButton groupName="supplierCaused" text="No" />
<RadioButton groupName="supplierCaused" text="No" />
</layout:ResponsiveFlowLayout>
<Label text="CBT"></Label>
<Select id="searchCBT" width="100%"></Select>
<Label text="Region" />
<layout:ResponsiveFlowLayout>
<RadioButton groupName="hisTransaction" text="Yes" />
<RadioButton groupName="hisTransaction" text="No" />
<RadioButton groupName="hisTransaction" text="No" />
</layout:ResponsiveFlowLayout>
</Page>
<!--
<Page id="detail" showNavButton="true" navButtonPress="onNavBack"
title="Product">
<Label text="Search Results" />
</Page> -->
</NavContainer>
<beginButton>
<Button text="Random" press="onDialogClose" />
</beginButton>
</Dialog>
</core:FragmentDefinition>
It will be a lot easier for me to answer you via pure javascript. Because in any way you need to attach a open handler to this dialog right? And separating the code will make this rather simple example really complicated one. So would something like that, putted in simple script tags work ?
var btn = new sap.m.Button({text:'Open Dialog', press: function(){oDialog.open();}});
var oDialog = new sap.m.Dialog({
showHeader : false,
stretch: sap.ui.Device.system.phone ? true : false,
beginButton : new sap.m.Button({
text : 'OK',
press : function() {
oDialog.close();
}
}),
contentHeight : "500px"
});
var oNavContainer = new sap.m.NavContainer();
var oPage = new sap.m.Page({
enableScrolling : true,
title : 'Test Page',
subHeader : new sap.m.Bar({
contentMiddle : new sap.m.Button({text:'SubHeader Button'})
}),
content : [ new sap.m.Button({text:'Content Button'}) ]
});
oNavContainer.addPage(oPage);
oNavContainer.setInitialPage(oPage);
oDialog.addContent(oNavContainer);
btn.placeAt('content');
</script>
You just need to have an div item with id = "content" and it should work :)