element_input.erl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. -module(element_input).
  2. -include_lib("nitro/include/nitro.hrl").
  3. -compile(export_all).
  4. render_element(Record) ->
  5. Id = case Record#input.postback of
  6. undefined -> Record#input.id;
  7. Postback ->
  8. ID = case Record#input.id of
  9. undefined -> nitro:temp_id();
  10. I -> I end,
  11. nitro:wire(#event{type=click, postback=Postback, target=ID,
  12. source=Record#input.source, delegate=Record#input.delegate }),
  13. ID end,
  14. List = [
  15. %global
  16. {<<"accesskey">>, Record#input.accesskey},
  17. {<<"class">>, Record#input.class},
  18. {<<"contenteditable">>, case Record#input.contenteditable of true -> "true"; false -> "false"; _ -> undefined end},
  19. {<<"contextmenu">>, Record#input.contextmenu},
  20. {<<"dir">>, case Record#input.dir of "ltr" -> "ltr"; "rtl" -> "rtl"; "auto" -> "auto"; _ -> undefined end},
  21. {<<"draggable">>, case Record#input.draggable of true -> "true"; false -> "false"; _ -> undefined end},
  22. {<<"dropzone">>, Record#input.dropzone},
  23. {<<"hidden">>, case Record#input.hidden of "hidden" -> "hidden"; _ -> undefined end},
  24. {<<"id">>, Id},
  25. {<<"lang">>, Record#input.lang},
  26. {<<"spellcheck">>, case Record#input.spellcheck of true -> "true"; false -> "false"; _ -> undefined end},
  27. {<<"style">>, Record#input.style},
  28. {<<"tabindex">>, Record#input.tabindex},
  29. {<<"title">>, Record#input.title},
  30. {<<"translate">>, case Record#input.contenteditable of "yes" -> "yes"; "no" -> "no"; _ -> undefined end},
  31. % spec
  32. {<<"autofocus">>,Record#input.autofocus},
  33. {<<"disabled">>, if Record#input.disabled == true -> "disabled"; true -> undefined end},
  34. {<<"name">>,Record#input.name},
  35. {<<"type">>, Record#input.type},
  36. {<<"max">>, Record#input.max},
  37. {<<"placeholder">>,Record#input.placeholder},
  38. {<<"min">>, Record#input.min},
  39. {<<"multiple">>, Record#input.multiple },
  40. {<<"value">>, nitro:js_escape(Record#input.value)},
  41. {<<"onkeypress">>, nitro:js_escape(Record#input.onkeypress)},
  42. {<<"onkeyup">>, nitro:js_escape(Record#input.onkeyup)},
  43. {<<"onkeydown">>, nitro:js_escape(Record#input.onkeydown)},
  44. {<<"onclick">>, nitro:js_escape(Record#input.onclick)},
  45. {<<"onchange">>, Record#input.onchange} | Record#input.data_fields
  46. ],
  47. wf_tags:emit_tag(<<"input">>, nitro:render(Record#input.body), List).