How to reuse forms?
I have two types of "listings". A create and and an edit page for each. Each form is slightly different. Before I had
CreateOrEditListing
which handled create/update for both types but I feel like these components quickly get incredibly complicated with a LOT of ugly if
statements.
Any ideas on how to deal with this?2 Replies
Ok I now just extracted everything to a
ListingForm
class where shared form logic resides
with parameters to customise aspects of the form
inheritance might also be an option
Works alright. Customisation options are provided through methods that can be overridden. Not sure what the best practice is, but I'll stick to this for now.
If anyone has better ideas, let me know pls :)Looks good to me, thanks for sharing that