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

Feature Request: Pass options to use:enhance #37

Closed
ElijahJohnson5 opened this issue Mar 16, 2023 · 11 comments
Closed

Feature Request: Pass options to use:enhance #37

ElijahJohnson5 opened this issue Mar 16, 2023 · 11 comments
Labels
done Implemented enhancements enhancement New feature or request next Will be implemented in the next release

Comments

@ElijahJohnson5
Copy link

Hello,

Really enjoying using the library. I am having some trouble where I want to be able to create the form at the top level and pass it down to components that handle using it. However these components want to set the options like onUpdate or onResult so I just have to pass the validation down to the component and create the form there.

If there is a better way to handle this that I am missing let me know. It is also hard to pass the form/validation all the way down to where the form actually is in my components since it may be deep in a component.

@ciscoheat
Copy link
Owner

There is a fields property returned from superForm that arranges the form data as objects with separate name, errors, etc properties. It has some kinks though, but it version 0.6.0 it will be much improved.

The events I'm not sure what you mean exactly, you want to be able to add events after calling superForm? How does the default enhance handle it?

@ciscoheat ciscoheat added the enhancement New feature or request label Mar 17, 2023
@ElijahJohnson5
Copy link
Author

You are able to use enhance like

use:enhance={() => {
  do something before submit
  return () => {
    do something with result  
  }
}

Currently with super form you have to pass those options into the superForm method which makes it a little more difficult. If instead I could pass options to the superForm enhance method that would be very nice

@ciscoheat
Copy link
Owner

Ah, good idea, will definitely implement that in a near release. Many of the options should be usable there. Any other options except the events that you may find interesting to use there?

@ciscoheat ciscoheat added next Will be implemented in the next release and removed next Will be implemented in the next release labels Mar 20, 2023
@ciscoheat ciscoheat changed the title Feature Request: Set enhance callbacks similar to the sveltekit default enhance Feature Request: Pass options to use:enhance Mar 21, 2023
@ciscoheat
Copy link
Owner

Removed the next label because it will take some consideration. Passing options in the enhance action will possibly conflict with the options set in superForm, and I'm not 100% sure how to handle that (overwrite, chain events together, etc?). Any ideas here are much appreciated.

@ElijahJohnson5
Copy link
Author

I would think they would overwrite the options passed in the superForm but am open to either way

@ciscoheat
Copy link
Owner

I'm thinking about what would happen if the action is used in several places. Is that what you had in mind, btw? :) If so, I think event chaining would be the best option, it's too easy to cause surprises when calling it in several unrelated places, otherwise.

@ElijahJohnson5
Copy link
Author

Yes multiple places is how I was/am using it. Chaining sounds good to me

@ciscoheat
Copy link
Owner

I think that will work fine, I'll start preparing that for the next release!

@ciscoheat ciscoheat added next Will be implemented in the next release done Implemented enhancements labels Mar 22, 2023
@ciscoheat
Copy link
Owner

@ElijahJohnson5 you should be able to pass events in use:enhance now:

<form method="POST" use:enhance={{onUpdated: ({form}) => ... }}>

Can you check that it works?

@ElijahJohnson5
Copy link
Author

Yes it works great! Thank you

@ciscoheat
Copy link
Owner

Nice, closing this then. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done Implemented enhancements enhancement New feature or request next Will be implemented in the next release
Projects
None yet
Development

No branches or pull requests

2 participants