Back to Spotube

Forms

website/src/content/docs/plugin-apis/forms.mdx

5.1.12.4 KB
Original Source

Spotube provides a Forms API that allows plugin developers to create and manage forms within the Spotube application.

Usage

Following will show a form with 2 text fields and text in between them:

hetu_script
import "module:spotube_plugin" as spotube

spotube.SpotubeForm.show(
  "The form page title",
  [
    {
      objectType: "input",
      id: "name",
      variant: "text",
      placeholder: "Enter your name",
      required: true,
    }.toJson(),
    {
      objectType: "input",
      id: "password",
      variant: "password", // This will obfuscate the input
      placeholder: "Enter your password",
      required: true,
    }.toJson(),
    {
      objectType: "text",
      text: "This is some text after the two fields.",
    }.toJson(),
  ]
).then((result) {
  // Handle the result
  print(result)
})

The method spotube.SpotubeForm.show takes a title and a list of form field declaration map. The map should be, well obviously a Map. Following are field map properties:

PropertyTypeDescription
objectTypetext or inputType of the object, should be text for text fields and input for input fields.
idStringUnique identifier for the field. (input type only)
variantStringVariant of the field, can be text, password or number. (input type only)
placeholderStringOptional placeholder text for the field. (input type only)
requiredBooleanWhether the field is required or not. (input type only)
defaultValueStringOptional default value for the field. (input type only)
regexStringOptional regex pattern to validate the input. (input type only)
textStringOptional text for text object type. (Only applicable for text type)

The method spotube.SpotubeForm.show returns a following format:

json
[
  {
    "id": "name",
    "value": "John Doe"
  },
  {
    "id": "password",
    "value": "12345678"
  }
]