blinkk / rootjs

Root.js – A full-featured web development tool with a built-in CMS.
https://rootjs.dev
MIT License
8 stars 0 forks source link

Add Lables to schema for array add buttons #443

Closed theroadeldorado closed 4 hours ago

theroadeldorado commented 5 hours ago

Description Would be really nice to be able to change the labels for the add buttons. It can get a bit confusing at times what you are adding.

schema.array({
  id: 'tags',
  label: 'Tags',
  preview: ['{tag}'],
  buttonLabel: 'Add Tag',
  of: schema.object({
    fields: [
      schema.string({
        id: 'tag',
        label: 'Tag',
        translate: true,
      }),
    ],
  }),
}),

example

stevenle commented 4 hours ago

@theroadeldorado this actually already exists as schema.array({buttonLabel: 'Add section'})

export type ArrayField = CommonFieldProps & {
  type: 'array';
  default?: any[];
  /**
   * String format for the preview line of an item in the array. Placeholder
   * values should use brackets, e.g. `m{_index:02}: {_type}`.
   *
   * Multiple values can be provided, in which case the first preview line with
   * no missing placeholder values will be used.
   *
   * System added placeholder values:
   *
   * - _index: The 0-based index.
   * - _index:02: A left-padded version of _index to 2 digits.
   * - _index:03: A left-padded version of _index to 3 digits.
   * - _type: For array of one-of fields, the type of the selected field.
   */
  preview?: string | string[];
  // NOTE(stevenle): the array field should only accept object values to keep
  // the schemas future-friendly. For example, if we were to accept primatives
  // (e.g. Array<string>) and the developer decides in the future that they
  // need to add extra fields to that array type, they would have to create a
  // new field, create a new schema field, and then perform a db migration to
  // update from the old field type to the new field type. But if we enforce
  // objects here, a developer should technically be able to add fields to the
  // nested field definition without breaking any existing db entries.
  of: ObjectLikeField;
  /**
   * Label to use for the "add item" button. Defaults to `Add`.
   */
  buttonLabel?: string;
};