constraintForm = (req, table, fields, type) => {
  switch (type) {
    case "Formula":
      return new Form({
        action: `/table/add-constraint/${table.id}/${type}`,
        onSubmit: "press_store_button(this)",
        fields: [
          {
            name: "formula",
            label: req.__("Constraint formula"),
            validator: expressionValidator,
            type: "String",
            class: "validate-expression",
            help: {
              topic: "Table formula constraint",
              context: { table: table.name },
            },
            sublabel:
              req.__(
                "Formula must evaluate to true for valid rows. In scope: "
              ) +
              fields
                .map((f) => f.name)
                .map((fn) => code(fn))
                .join(", "),
          },
          {
            name: "errormsg",
            label: "Error message",
            sublabel: "Shown to the user if formula is false",
            type: "String",
          },
        ],
      });
    case "Unique":
      return new Form({
        action: `/table/add-constraint/${table.id}/${type}`,
        blurb: req.__(
          "Tick the boxes for the fields that should be jointly unique"
        ),
        onSubmit: "press_store_button(this)",
        fields: [
          ...fields.map((f) => ({
            name: f.name,
            label: f.label,
            type: "Bool",
          })),
          {
            name: "errormsg",
            label: "Error message",
            sublabel: "Shown to the user if joint uniqueness is violated",
            type: "String",
          },
        ],
      });
    case "Index":
      const fieldopts = fields.map((f) => ({ label: f.label, name: f.name }));
      const hasIncludeFts = fields.filter((f) => f.attributes?.include_fts);
      if (!db.isSQLite)
        fieldopts.push({ label: "Full-text search", name: "_fts" });
      return new Form({
        action: `/table/add-constraint/${table.id}/${type}`,
        blurb: req.__(
          "Choose the field to be indexed. This make searching the table faster."
        ),
        onSubmit: "press_store_button(this)",
        fields: [
          {
            type: "String",
            name: "field",
            label: "Field",
            required: true,
            attributes: {
              options: fieldopts,
              explainers: hasIncludeFts
                ? {
                    _fts: "Full text search index is not compatible with Key fields with the 'Include in Full text search' option. A new field will be created for your search context",
                  }
                : {},
            },
          },
        ],
      });
  }
}
Constraint Fields Edition Form
Choosing fields for adding to contrain
@param req
@param {string} table_id
@param {object[]} fields
@returns {Form}