koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
553 stars 156 forks source link

Slot for labels #161

Closed sobrinho closed 3 months ago

sobrinho commented 4 years ago

Another interesting use case, we wanted to titleize all labels from the model key instead of defining every single one in the schema.

We came with this:

import VJsf from "@koumoul/vjsf";
import titleize from "@/helpers/titleize";

// Dirty inheritance from VJsf because TypeScript is not happy with inheriting
// from a 3rd party component.
export default {
  ...VJsf,

  computed: {
    ...VJsf.computed,

    // Render the label as the model key in titleized format.
    //
    // This will avoid duplicated definitions in the widget form schema and any
    // odd titles can be explicitly set.
    label () {
      return this.fullSchema.title || (typeof this.modelKey === 'string' ? titleize(this.modelKey) : '')
    }
  }
}

Ignore the typescript hack (still working on that) but pay attention that I wanted to overwrite the default behavior for the label using a helper of mine.

Maybe a slot for the label would be more appropriate, wdyt?

sobrinho commented 4 years ago

Allowing a slot would allow using any kind of specialized labels like i18n'ing them! ;)

sobrinho commented 3 months ago

Not stale.