Skip to Content
avatar image
Former Member

how can i set the OModelData binding with radiobutton

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.

unbenannt.png (45.5 kB)
unbenannt2.png (62.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    Mar 27, 2017 at 01:49 PM
    <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.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 27, 2017 at 02:27 PM

    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

    Add comment
    10|10000 characters needed characters exceeded