cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how can i set the OModelData binding with radiobutton

Former Member
0 Likes
867

hello,

i want set a flag property in my OModelData with a radiobutton from my View. if radiobutton in a form set true or false, then i get a 1 or 0 to my Flag of OModelData.

<Label text="Billable" />
<RadioButtonGroup columns="3" width="500px" id="flag" selectedIndex="{appointments>flag}">
	<buttons>
		<RadioButton text="true"/>
		<RadioButton  text="false"/>
	</buttons>
</RadioButtonGroup>
...........

<semantic:saveAction>
	<semantic:SaveAction id="save"  press="onSave"/>
</semantic:saveAction>

But on the frontend they must be displayed yes or no not 1 or 0.

So I implemented in my onsave function if segment.

onSave: function() {
	var setFlag = this.getView().byId("flag").getSelectedIndex();

if(setFlag == "1") {
	this.getModel("appointments").setProperty("flag", "No"); 
	console.log("1");
} else if(setFlag == "0"){ 
	this.getModel("appointments").setProperty("flag", "Yes"); 
	console.log("0");
}			
	this.getModel("appointments").submitChanges();
		}

And I have also tried other possibilities:

this.getModel("appointments").setProperty("/flag", "No"); 
or
this.getView().getModel("appointments").setProperty("/flag", "No"); 
or
sap.ui.getCore().getModel("appointments").setProperty("/flag", "true")

All of this can not set the flag property to yes or no.

my metadate:

<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
	<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0"
					   xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
		<Schema Namespace="timeTrackertimeTracker" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
			<EntityType Name="appointments">
				<Key>
					<PropertyRef Name="Id"/>
				</Key>
				<Property Name="Id" Type="Edm.String" Nullable="true" />
				<Property Name="projektnummer" Type="Edm.String" Nullable="false" />
				<Property Name="title" Type="Edm.String" Nullable="false"/>

				<Property Name="starttime" Type="Edm.String" Nullable="false" />
			    <Property Name="endtime" Type="Edm.String" Nullable="false" />
			    <Property Name="duration" Type="Edm.Byte" MaxLength="2" Nullable="false" />
			    <Property Name="rest" Type="Edm.Byte" Precision="16" Scale="3" MaxLength="2" Nullable="false" />
			   
			    <Property Name="flag" Type="Edm.String"/>
				<Property Name="description" Type="Edm.String" Nullable="true"/>
			</EntityType>
		</Schema>
		<Schema Namespace="timeTrackertimeTracker.Model" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
			<EntityContainer Name="timeTrackertimeTrackerEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true"
							 xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
				<EntitySet Name="appointments" EntityType="timeTrackertimeTracker.appointments"/>
			</EntityContainer>
		</Schema>
	</edmx:DataServices>
</edmx:Edmx>

how can i do it to set the flag propety to "yes" or "no", if the radiobutton is selected.

Accepted Solutions (1)

Accepted Solutions (1)

junwu
SAP Champion
SAP Champion
0 Likes
<RadioButtonGroup columns="3" width="500px" id="flag" selectedIndex="{appointments>flag}"><buttons><RadioButtontext="false"/><RadioButtontext="true"/></buttons></RadioButtonGroup>

this should be enough for the radio group, you don't have to do anything

for that table, you can use a formatter to convert the value.

Mathias_Uhlmann
Product and Topic Expert
Product and Topic Expert
0 Likes
Another option would have been to bind against the selected property of the RadioButton for true and to use the type sap.ui.model.odata.type.Boolean for the binding in the table.

Answers (1)

Answers (1)

Former Member
0 Likes

Hi,

You just have to use expression binding or a formatter to display yes for 1 and no for 0 in the table.

Cheers,

Pierre