Requiring Fields for commands

This was intended for documentation but slipped...

The command definition in drivers allows now for an optional 3 map to be passed into commands

Original code:
command "testEnum", ["Enum"]

resulted in this:
image

with 2.0 we added support for defining a few things:
command "testEnum", [[name:"Testing Enum", type: "ENUM", description: "Pick an option", constraints: ["one","two","three"] ] ]

will result in this:
image

What has happened is we have expanded the 2nd parameter to command to allow 4 elements in the map, name, type, description and constraints.

Name is the value that shows up where "ENUM" used to be, directly above the input. If the name ends with an asterisk (*) it will be considered required and the input box will be red and the button will not submit without a value

Type is one of the following, STRING, NUMBER, ENUM, COLOR_MAP, or JSON_OBJECT

NUMBER will constrain it to numbers +/- and decimal

ENUM allows for the constraint to be added to the select input

COLOR_MAP invokes the color picker, which can only be one on the device screen.

Description is used for the hover over of the input field. Useful in defining what the custom command is expecting, ex. Please enter a number between 1 and 100

As for Constraints, at this point it is only used for populating ENUM values but is reserved for future use.

Couple other things to note. The ENUM list is static and cannot be updated in any way shape or form from the driver, inputs, etc.

There is no validation (other than NUMBER and * being required) on inputs, this is up to the methods to handle this properly.

This is not meant to replace the preferences area, its just a way to refine the custom commands to display name, a hover over or drop down.

7 Likes