josemarluedke / frontile

Component Library for Ember Octane apps
https://frontile.dev
MIT License
54 stars 21 forks source link

ChangesetForm: @onSubmit data arg is undefined #218

Open mcfiredrill opened 2 years ago

mcfiredrill commented 2 years ago

I'm trying to use the @onSubmit function for changeset forms. The data arg is always undefined.

result seems to just be the changeset that was saved. I see a data property in the changeset docs, but for me it's undefined even though the changeset saved successfully. https://github.com/poteto/ember-changeset#data

Maybe simply returning the changeset will be the most flexible for users of this API?

chsanch commented 1 year ago

As a workaround for this (I need the id for the newly created model object) I'm creating the changeset on the component:

changeset  = new Changeset(
    this.args.model,
    lookupValidator(this.validations),
    this.validations
  );

and in the function I used for the @onSubmit in the ChangesetForm I can get the id from the component's changeset :

@action
  handleSubmit(data, event) {
      this.router.transitionTo(
        'route.for.redirection',
        this.changeset.get('id')
      );
  }

But yes, I agree it's better if the @onSubmit function returns the changeset on the data attribute