<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: How to avoid model changes using selected key in sap.m.select? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216480#M4572292</link>
    <description>&lt;P&gt;glad it worked.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Sep 2020 08:41:36 GMT</pubDate>
    <dc:creator>Ricardo___</dc:creator>
    <dc:date>2020-09-02T08:41:36Z</dc:date>
    <item>
      <title>How to avoid model changes using selected key in sap.m.select?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaq-p/12216477</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Select id="selApplication" forceSelection="false" change="handleChangeApplication" selectedKey="{/Applications/0/Application}" items="{path: '/Applications'}"&amp;gt; 
&amp;lt;core:Item key="{Application}" text="{Name}"/&amp;gt;
 &amp;lt;/Select&amp;gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;I am using the above code snippet.&lt;/P&gt;
  &lt;P&gt;The JSONModel looks like this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;{ 
"Applications": [{ 
    "Application": "GRN", 
    "Name": "Goods Receipt Note"
    },
    { 
    "Application": "NPO",
    "Name": "Non-PO Invoice Approval"
     }] 
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;On initial load of application the Model remains same as above.&lt;/P&gt;
  &lt;P&gt;But when I change the selection in UI from GRN to NPO, on debugging the application in handleChangeApplication method, the Model changes to following:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;{
"Applications": [{ 
    "Application": "NPO", 
    "Name": "Goods Receipt Note"
    },
    { 
    "Application": "NPO",
    "Name": "Non-PO Invoice Approval"
     }] 
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt; As we can see, the Application value is automatically changed, this is causing issues.&lt;/P&gt;
  &lt;P&gt;Please help me in understanding where I am going wrong. Is this an issue with how I am binding the selectedKey?&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 05:28:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaq-p/12216477</guid>
      <dc:creator>former_member695380</dc:creator>
      <dc:date>2020-09-02T05:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid model changes using selected key in sap.m.select?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216478#M4572290</link>
      <description>&lt;P&gt;I think this has to do with a reference problem in javascript objects, to avoid this I usually define a new property in the model.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Select id="selApplication" forceSelection="false" change="handleChangeApplication" selectedKey="{/sSelectedKeyApplication}" items="{path: '/Applications'}"&amp;gt;
	&amp;lt;core:Item key="{Application}" text="{Name}"/&amp;gt;
&amp;lt;/Select&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;//we define the key of the first element of the array
var aApplications = oModelJson.getProperty("/Applications");
var sKeyApplication = aApplications[0].Application;
oModelJson.setProperty("/sSelectedKeyApplication",sKeyApplication);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I hope it helps.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 08:07:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216478#M4572290</guid>
      <dc:creator>Ricardo___</dc:creator>
      <dc:date>2020-09-02T08:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid model changes using selected key in sap.m.select?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216479#M4572291</link>
      <description>&lt;P&gt;Hi Ricardo,&lt;/P&gt;&lt;P&gt;It works fine. Thank you.&lt;/P&gt;&lt;P&gt;Also, went through the Chrome console to find that the default binding is 2 way. We can also use the below snippet to change it to OneWay.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After the call, all future model assignments will be one way after this call.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 08:35:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216479#M4572291</guid>
      <dc:creator>former_member695380</dc:creator>
      <dc:date>2020-09-02T08:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to avoid model changes using selected key in sap.m.select?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216480#M4572292</link>
      <description>&lt;P&gt;glad it worked.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 08:41:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-avoid-model-changes-using-selected-key-in-sap-m-select/qaa-p/12216480#M4572292</guid>
      <dc:creator>Ricardo___</dc:creator>
      <dc:date>2020-09-02T08:41:36Z</dc:date>
    </item>
  </channel>
</rss>

