aesmail / kaffy

Powerfully simple admin package for phoenix applications
https://kaffy.fly.dev/admin/
MIT License
1.3k stars 153 forks source link

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

Open dorianamouroux opened 1 year ago

dorianamouroux commented 1 year ago

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