Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternative API for handling controls #83

Open
jelhan opened this issue Mar 15, 2023 · 0 comments
Open

alternative API for handling controls #83

jelhan opened this issue Mar 15, 2023 · 0 comments

Comments

@jelhan
Copy link

jelhan commented Mar 15, 2023

This library looks very promising. Thanks a lot for working on it!

I'm not fully convinced by the public API for controls yet. Currently <form.Field> yields different build-in control components:

  • input
  • textarea
  • checkbox
  • radio group
  • select

Custom controls needs to be used for everything else.

To use a custom control, <form.Field> and the control component needs to be wired manually. This prevents community from building reusable controls to integrate other libraries with ember-headless-form. It seems custom controls were a second thought when designing the API.

I like to propose an alternative API for controls. Let me illustrate it using first-class component template syntax:

import { Input, Textarea } from 'ember-headless-form/controls';
import { PowerSelectMultiple } from 'ember-headless-form-power-select';
import pickaday from 'ember-pickaday/modifiers/pickaday';

<template>
  <HeadlessForm as |form|>
    <form.Field @name='title' @control={{Input}} as |field|>
      <field.Label>Title</field.Label>
      <field.Control />
    </form.Field>

    <form.Field @name='body' @control={{Textarea}} as |field|>
      <field.Label>Body</field.Label>
      <field.Control />
    </form.Field>

    <form.Field @name='tags' @control={{PowerSelectMultiple}} as |field|>
      <field.Label>Body</field.Label>
      <field.Control  />
    </form.Field>

    <form.Field @name='date' as |field|>
      <field.Label>Date</field.Label>
      <input
        id={{field.id}}
        {{pikaday
          format='DD.MM.YYYY'
          value=field.value
          onSelect=field.setValue
        }}
      />
    </form.Field>

    <button type='submit'>Submit</button>
  </HeadlessForm>
<template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant