thombruce / tnt

Thom's Nuxt Template
https://tnt.thombruce.com/
MIT License
1 stars 0 forks source link

Better Forms #68

Closed thombruce closed 4 months ago

thombruce commented 4 months ago

closes #28

By submitting this pull request, you agree to follow our Code of Conduct: https://github.com/thombruce/.github/blob/main/CODE_OF_CONDUCT.md


Internal use. Do not delete.

thombruce commented 4 months ago

Still todo:

thombruce commented 4 months ago

We should also...

This might be best done using Nuxt's utils/ folder: https://nuxt.com/docs/guide/directory-structure/utils

thombruce commented 4 months ago

Out of scope here, but we have the beginnings of a novel component idea. Call it something like FromYaml or ComponentsFromYaml or FromSerialized (since this would probably work with JSON and TOML too).

  template(v-for="component in body")
    component(
      :is="tntComponents.includes(_keys(component)[0]) ? `tnt-${_keys(component)[0]}` : _keys(component)[0]"
      v-bind="{ ..._omit(_values(component)[0], ['validate', 'rules']), ...{ fullErrors } }"
    )
      template(v-if="typeof _values(component)[0] === 'string'") {{ _values(component)[0] }}
      template(v-else-if="_keys(component).includes('body')") {{ component.body }}

Notice that on the last line, instead of rendering component.body inside of a template, we could pass component.body to the top template(v-for="component in body") component and have deeply nested components rendered from YAML files.

A rare use case, since the same could more easily be achieved from a .md file... but could prove useful for more than just the form layout. Worth creating the component anyway, even if only to simplify the TntForm.vue component.

thombruce commented 4 months ago

Inputs needing new Vee-validate + Yup logic:

thombruce commented 4 months ago

Excepting Combobox, there are two remaining to do. For radios and checkboxes, see: https://vee-validate.logaretm.com/v4/examples/checkboxes-and-radio

thombruce commented 4 months ago

Caveats on the checkbox and radio front:

  1. According to the docs for VeeValidate, the current setup is going to be invalid if used outside of a form - easy solution: just always use a form. I experimented with use of useForm, but this separates their values from the parent form schema. It should be an exercise for the developer as to which solution is best for any given scenario.
  2. I'm not sure that either checkbox or radio emit appropriate values - they were both created hastily and haven't actually been used in a live scenario yet. The conversion to VeeValidate, I fear, compounds this issue... particularly for singular checkboxes. Each need a revisit and a refactor. I will create a new issue to handle this.