【发布时间】:2016-03-19 05:48:14
【问题描述】:
我尝试扩展 phoenixframework 的 Phoenix.HTML.Form 模块。我的意图是包装 html 表单帮助器 text_input 来为 timex 日期值创建一个文本输入字段,以便与 bootstrap-datepicker 一起使用。
我是 elixir 新手,但我阅读了有关扩展 elixir 模块的协议。所以我尝试了:
defprotocol Phoenix.HTML.Form.Extension do
def timex_date_input(form, field, opts \\ [])
end
defimpl Phoenix.HTML.Form.Extension, for: Phoenix.HTML.Form do
def timex_date_input(%{model: model, params: params}, field, opts \\ []) do
# my logic goes here
form = %{model: model, params: params}
text_input(form, field, opts)
end
end
但是,它不起作用,因为:“function text_input/3 undefined”。什么是正确的解决方案?
【问题讨论】:
标签: html forms helper elixir phoenix-framework