element_datetime_local.erl 2.7 KB

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