Search code examples
google-app-maker

Create keywords list WITHIN Create with MANY to MANY relation


I'd like to build a simple creation/edition system where one can create a Challenge that contains many Keywords. Here is the data I created:

Challenge <---- MANY to MANY -----> Keywords

Now, I'm struggling building my Challenge creation form because I'm trying to embed the keywords selection on the CREATE page of the challenge itself. Here is what it looks like:

Screenshot for Challenge creation enter image description here

This is the Challenge creation page. It contains name, description (challenge model fields) and also a dropdown that goes with a grid, both dedicated to keywords for this challenge. Thanks to a script, I successfully add an keyword item to the Grid datasource when the user selects a value:

/**
 * Adds a Keyword to the list of Keywords
 * If already added then does nothing.
 * @param {Widget} widget - widget that triggered the event.
 * @param {Keyword} newValue - record object of selected keyword.
 */
function addKeyword(widget, newValue) {

  var ds = app.pages.CreateChallenge.descendants.KeywordsGrid.datasource;
  ds.items.push({
    KeywordId: newValue._key,
    KeywordName: newValue.Name
  });

  widget.value = null;
}

Once the keywords are added, my problem is that I don't know how to link the newly filled grid full of keywords to the New Challenge in creation so that it populates it with those keywords. Here is what it looks like on the Grid object:

Screenshot for grid enter image description here

Can I achieve that with bindings only? Should I script it? Any help is welcome. I guess my question is actually : how to bind a grid to an object in creation (and edition) on a relation between this object and other ones?


Solution

  • Finally solved it after hours. I used :

    @datasources.Challenge.modes.create.item.ChallengeKeyword
    

    It allows to handle the data for the item that is being processed by the creation "mode".