A2v10 Platform documentation
UK


Templates. Commands

The object describing commands in the template is a regular JavaScript object. The property names of this object are command names, and the values are functions or objects.

Commands in views are specified using the BindCmd binding with the Command property set to Execute or ExecuteSelected. The name of the command is specified by the CommandName property.

Syntax


If the value is a function, then it is simply called when the command is executed.

Command object properties

  • {Function} exec - function executing the command.
  • {Function} canExec - a function that determines whether a command can be executed. Returns an indication of whether the command can be executed. The value is cast to the Boolean type.
  • {Boolean} saveRequired - whether the model needs to be saved before executing the command. Can also be set in the BindCmd binding using the SaveRequired property.
  • {Boolean} validRequired - execute command only for the model that has passed validation($valid property of root object = true. Can also be set in the BindCmd binding using the ValidRequired.
  • {Boolean} checkReadOnly - forbid command for model in “read-only” state. Can also be set in the BindCmd binding using the CheckReadOnly property.
  • {String|Object} confirm - ask for user confirmation before executing the command. Can also be set in the BindCmd binding using the Confirm property. If the value is a string, then it is considered a confirmation text. If it is an object, then it has the structure shown below.

Confirm object properties

  • {String} message - message text.
  • {String} title - the title of the message box. If not specified, will be locale.$Confirm.
  • {String} okText - text on the confirmation button. If not specified, will be locale.$Ok.
  • {String} cancelText - text on the cancel button. If not specified, will be locale.$Cancel.

Exec and canExec function arguments

  • this - root object (TRoot).
  • arg - the argument passed to the command. If the command is specified in markup, the argument is specified by the Argument property (or binding) of the BindCmd object.

Please note! User interface elements associated with commands (for example buttons) will be automatically forbidden or allowed depending on the ability to execute the command. It is not necessary to use the Disabled property.

Example

XAML:


Javascript: