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] Simpler way to use a custom widget #268

Open
dorianamouroux opened this issue Apr 20, 2023 · 0 comments
Open

[FEATURE-REQUEST] Simpler way to use a custom widget #268

dorianamouroux opened this issue Apr 20, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@dorianamouroux
Copy link

Describe the problem you're proposing to solve

Thanks for building and maintaining this great package! I’ve been trying it for my project, and so far it has been working great. But there is one use-case that I think could get some extra attention.

In order to be able to customise an input field for a given type, we need to add a couple of functions in the module of the Ecto type.

While it works, I believe it goes against one of the driving point: Existing schemas/contexts shouldn't have to be modified./ I shouldn't have to change my code in order to adapt to the package, the package should adapt to my code.; as we need to create/modify a custom type in order to change the form.

Describe the solution you'd like

I believe what would make more sense, is to be able to give Kaffy a specific module to be used to render the input field, where the functions render_form/5 & render_index/3 could sit. That way, we can easily create a new module to customise the input of a given field, without modifying the underlying code. That approach can also enable using a “better ui” when we want a specific widget to be used for a field.

Describe alternatives you've considered

N/A

Additional context

A couple of pain point I had, which this solution would solve:

Example 1: In my model I have a field called published_at which will contain the timestamp when the object was published, and nil if not published. In my Admin dashboard, I would prefer to use a checkbox, rather than a time select field. The logic to transform the boolean to the current date can eventually be done in before_insert hook.

Example 2: I’m using embedded schema, which are rendered as JSON on a textarea, I believe I could build a better field that fits better my use-case. I tried to put render_form/5 and render_index/3 in the model definition, but it wasn’t working. With my suggested approach, I could simply pass my custom module to

Hope it makes sense. Let me know what you think

@dorianamouroux dorianamouroux added the enhancement New feature or request label Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants