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

lion-form: custom form using slot #2027

Open
nbamfordcirium opened this issue Jun 29, 2023 · 0 comments
Open

lion-form: custom form using slot #2027

nbamfordcirium opened this issue Jun 29, 2023 · 0 comments

Comments

@nbamfordcirium
Copy link

Expected behavior

I would like to customize lion-form to a custom form component that could contain arbitrary form controls, like the following:

import {
  LitElement,
  customElement,
  property,
  html,
} from '@lion/core';

import '@lion/form/define';
import '@lion/button/define';

@customElement('my-form')
export class MyForm extends LitElement {
  @property() submitHandler?: (formData: FormData) => void;

  _handleSubmit = (event) => {
    const formData = event.target?.serializedValue;

    if (this.submitHandler) {
      this.submitHandler(formData);
    }
  };

  render() {
    return html`
      <lion-form @submit="${this._handleSubmit}">
        <form>
          <slot></slot>
          <lion-button-submit>Submit</lion-button-submit>
        </form>
      </lion-form>
    `;
  }
}

and then it would be used like:

<my-form>
  <lion-input label="Name"></lion-input>
</my-form>

Actual Behavior

Unfortunately, I can't seem to make the live code samples import lion components beyond the tooltip, but though the submit is called as I would expect, the form serializedValue is always empty.

Is there any way for me to derive a customized lion-form in this way?

Additional context

lion-form:0.15.0

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