user8278795
user8278795

Reputation:

Changing the title of the header

I use the SAPUI5 Framework. Within a page there are two possibilities for action, to make a new patient and to edit a patient. The new and edit, control/view pages are compiled into one, one control and one view for both new and edit.

Since they both are within one-page control/view, whenever I try to make a new patient or to edit a patient I get the same title for both of these Options.

My approach.

  1. Get the URL of the page -> New or Edit. -> Split till I get, if it's new or edit.
  2. If its new, change the title to New if edit that the title to Edit.
var completurl = window.location.href;
var split = completurl.split("/");
if(split[7] == 'new'){
   this.byId("semantic:DetailPageID").setTitle("New");
}  
else {
  this.byId("semantic:DetailPageID").setTitle("Edit");
}               

Expected: To change the title of the header. Actuality: Doesn't do shit

Upvotes: 0

Views: 85

Answers (1)

alexP
alexP

Reputation: 3765

First you need the different buttons in your main.view.xml.

main.view.xml:

<Button press="onPressNew" text="New"/>
<Button press="onPressEdit" text="Edit"/>

Now you could use a local model for saving the action

editNew.controller.js:

onPressEdit: function () {
    this.myLocalModel.setProperty("/Action", "Edit");
    //Navigate to editNew.view.xml
},
onPressNew: function () {
    this.myLocalModel.setProperty("/Action", "New");
    //Navigate to editNew.view.xml
}

In your editNew.view.xml, you could use expression binding

editNew.view.xml:

<Page id="pageEditNew" title="{= ${localModel>/Action} === 'Edit' ? ${i18n>title_edit} : ${i18n>title_new}}">

Upvotes: 2

Related Questions