Search code examples
sapui5

Change button class conditionally based on OData Model


I have a basket, each line containing a button with a tooltip which displays if any internal or Supplier Notes haves been entered. Here's the view code:

<Button text="" icon="sap-icon://notes" tooltip="    {i18n>ReviewBasket.SupplierNote}: {basket>SupplierNote} {i18n>ReviewBasket.InternalNote}: {basket>InternalNote}" press="openSupplierNote"/>​

This is great, but I want to change the type of the button to Emphasized if either internal or supplier notes exist.

I've so far logged the model data, which contains all the info.

OData: Object
     items: Array[1]
          0: Object
              SupplierNote: "Test1
              InternalNote: "Test2"

Any suggestions?


Solution

  • You can set the button type with an expression binding.

    <Button 
        icon="sap-icon://notes" 
        type="{= (${basket>InternalNote} === '' &amp;&amp; ${basket>SupplierNote}) ? 'Accept' : 'Emphasized'}"
        press="openSupplierNote"/>