Question

i have got an textField :

  var favInput = new sap.ui.commons.TextField("tfFavorites",{
  value : 'Give a name to the favorite....',
  imeMode: sap.ui.core.ImeMode.Active,
 editable: true  });

and i have got an button :

 var saveFavorButton = new sap.ui.commons.Button({  text : "Create new favorite" });

on a press on the button, i want to build a "createNewFavorite" function which will create a link with the name of the user text input. as example :

var myFavorites1 = new sap.ui.commons.Link("myfav1",{
      text: "my favorite 1",
              });

how to create "createNewFavorite" function? many thanks!

Was it helpful?

Solution

You can use something like:

saveFavorButton.attachPress(function() {
    var myFavorites1 = new sap.ui.commons.Link("myfav1",{
        text: favInput.getValue()
    });
    //now you just need to add the new control to your view
});

but a better way would be to create a (JSON) model which you then bind to your TextField, and which you can then grow and/or shrink to cater for more favourites to be stored

OTHER TIPS

In the properties of button, you can add a property PRESS in which you can define your function createNewFavorite as follows:

var saveFavorButton = new sap.ui.commons.Button( {
text : "Create new favorite", press : function() { var myFavorites1 = new sap.ui.commons.Link("myfav1", { text: favInput.getValue() }); } });

or else you can write "press : createNewFavorite" and you can define this function createNewFavorite in the controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top