I’m trying to solve a tricky problem, so I’ve made a twiddle to demonstrate it:
Here’s my problem, basic idea is to allow consumers define template of each selection and selected item for component, so I exposed the each selection for {{auto-complete-datalist}} and current selected item for {{auto-complete-input}}. Since we need to control how to render them (use customized HTML tags), so I have to use a div
with contenteditable=true
.
Now, you can focus in the input, select an option, then display the result as user defined form. But! you can’t DELETE the current selected item! because if you do that, you will also delete the customized template, so it won’t show again after deletions.
I don’t know how to archive this goal, many similar plugins will use a template option which allow user to provide a string HTML fragment, the plugin will render this at the runtime. It seems like a accept way but I don’t know how to allow consumers provide a string HTML template with handlebars tags in it?
How will you make this happen? Any suggestions will be appreciated.