Skip to Content

Databinding on formfield with path not working

Hey there,

I have a XML-form with odata-binding. Normal binding to fields is working.

But the binding with value="{ path: ...}" is not working.

I have some dates to show, and all I get from SAP is /Date(1512086400000)/. I want to format this as shown on Text-tag.

Form.

<form:SimpleForm
			layout="ResponsiveGridLayout"
			editable="true"
			id="bestForm" >
			<Label displayOnly="true" wrapping="true" text="Bestellung" for="edtEBELN" required="true"/>
			<Input id="edtEBELN" change="onEbelnChange" valueLiveUpdate="true"></Input>
			<Label displayOnly="true" wrapping="true" text="Lieferschein" for="edtLIEFS" required="true"/>
			<Input id="edtLIEFS" change="onLiefsChange" value="{bestellung>Bktxt}" valueLiveUpdate="true"></Input>
			<Label displayOnly="true" wrapping="true" text="Belegdatum" for="edtBELDAT" required="true"/>
			<Input id="edtBELDAT" change="onBeldatChange" value="{/d/Lfdat}" valueLiveUpdate="true"></Input>
			<Label displayOnly="true" wrapping="true" text="Lagerort" for="edtLGORT"/>
			<Input 
				id="edtLGORT"
				editable="false" 
				value="{/d/Lgort}"
				valueLiveUpdate="true" />
			<Label displayOnly="true" wrapping="true" text="Bestelldatum" for="edtBESTDAT"/>
			<Input id="edtBESTDAT" 
				editable="false" 
				value="{/d/Bestdat}" 
				valueLiveUpdate="true"
				/>
				<Label displayOnly="true" wrapping="true" text="Text" for="txt"/>
				<Text id="txt" text="{
  path: '/d/Bestdat',
  type: 'sap.ui.model.type.Date',
  formatOptions: {
  style: 'long',
  source: {
  pattern: 'yyyy/MM/dd'
  }
  }
  }" valueLiveUpdate="true"/>
				
			<Label displayOnly="true" wrapping="true" text="Anforderer" for="edtANFORD"/>
			<Input id="edtANFORD" editable="false" value="{/d/Lgnum}" valueLiveUpdate="true"></Input>
			</form:SimpleForm>

JS with Binding:

var url = "http://----:---/sap/opu/odata/sap/ZWM_MDE_SRV_03/BESTSet(Ebeln='"+ebeln+"',Lgnum='110')";
		var oModel = new sap.ui.model.json.JSONModel(url, true);
		this.getView().setModel(oModel);
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Dec 18, 2017 at 03:16 PM
    data-sap-ui-xx-bindingSyntax="complex"

    this line has to be in header script...

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 02, 2017 at 04:16 AM

    Hi Sven Schuberth,

    You can format date in your XML view like the foll.

    <Text text="{
             path: 'Name-Of-Your-Date-Field',
             type: 'sap.ui.model.type.Date',
             formatOptions: {
               pattern: 'yyyy/MM/dd'                    //Here you can pass any pattern as per your requirement
             }
    

    Apart from this, you can define an formatter function and modify your date format there.

    Hope this helps,

    Regards.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 04, 2017 at 07:38 AM

    Hi Arjun Biswas,

    unfortunately it doesn't work. I think it's not a problem with the pattern. Instead the binding isn't working properly.

    This is my datasource json-model:

    {"d":{"__metadata":{"id":"http://xxx/sap/opu/odata/sap/ZWM_MDE_SRV_03/BESTSet(Ebeln='45',Lgnum='110')","uri":"xxx/sap/opu/odata/sap/ZWM_MDE_SRV_03/BESTSet(Ebeln='45',Lgnum='110')","type":"ZWM_MDE_SRV_03.BEST"},"Ebeln":"45","Lgnum":"110","Lgort":"1200","Bestdat":"\/Date(1512086400000)\/","Lfdat":"\/Date(1512086400000)\/","Bktxt":""}}

    If I bind directly, it works:

    <Text text="{/d/Bestdat}" />

    But if I bind via the following code it doesn't show anything:

    <Text text="{ path: '/d/Bestdat' }" />

    Any suggestions?

    Kind regards - Sven

    Add comment
    10|10000 characters needed characters exceeded