Take

Take determines the input fields that will be supplied to the make function. It is typically a flat array of field objects.

({
  take: [ 
    { type: "text", value: "String" },
    { type: "toggle", value: true },
    { type: "number", value: 123 },
  ],
})

The code above will render three fields — a text field, a toggle and a number field.

Short-hand statements

If only one input is needed, there is no need to wrap the field in an array. Instead, pass it directly to take.

({
  take: { type: "json" }
})

When needed, take may also be a function that returns such an array or object.

({
  take: function () {
    return {
      type: "dropdown",
      options: ["Small", "Medium", "Large"],
    }
  },
})

Asynchronous code

If you need to run an asynchronous process, take can be an async function or return a Promise.

({
  // Declaring an async function
  take: async () => {
    const request = await fetch("https://example.com/some/json")
    return await request.json()
  },

  // Returning a Promise
  take: () => {
    return new Promise(function(resolve) {
      resolve([{ type: "text" }])
    })
  },
})

Default value

When take is null or undefined, the default input is a single text field.

({
  // A make function with no take definition
  make: (data) => {
    return typeof data // => "string"
  },
})

No inputs

In cases where no inputs are necessary, you can set the value to an empty array. In this case, no input fields are rendered.

({
  take: []
})