Create a Tab with a command form

Step 1: create a tab with the form

In this example we make a tab for the “greet” command of the “person” element.

// A command form is expanded for each command
var PersonGreetForm = require('tutorialComp/person-greet-form');

// ...

var tabs = /*...*/ // create tabs of reuse for example the waterfall tabs

var commandForm = PersonGreetForm.defineCommandForm({
  data: {},
  target: personList.selection, // we'll use the selection of a list as target
  layoutConfig: {}
});

// we'll wrap our form with the command-form template
var greetTab = tabs.defineTab({
  name: "greet",
  view: "nsx/knockout/command-form",
  viewModel: {
    title: "Greet",
    submitText: translate("ns.confirm"),
    submit: commandForm.submit // the command-form template has a submit button
    // that will trigger the command
  }
});

// the form is injected into the <content> tag within the command-form template
greetTab.definePageSegment({
  selector: "content",
  view: "alpha/person-greet-form", // this file is generated by the expanders
  // for each command
  viewModel: commandForm
});

Step 2: inject an errorView into the template to show ‘global’ errors

// we can also inject an errorView component in order to show the error messages
// of the command within the template
var errorView = ErrorView.defineErrorView({
  level: ErrorLevel.all,
  priority: ErrorPriorities.pageBody
});

greetTab.definePageSegment({
  selector: "errors",
  view: "nsx/knockout/errorMessages",
  viewModel: errorView
}, {
  visible: true
});