element_input.erl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. -module(element_input).
  2. %%-author('Maxim Sokhatsky').
  3. -include_lib("nitro/include/nitro.hrl").
  4. -compile([export_all, nowarn_export_all]).
  5. render_element(Record) ->
  6. Id = case Record#input.postback of
  7. undefined -> Record#input.id;
  8. [] -> Record#input.id;
  9. Postback ->
  10. ID0 = case Record#input.id of
  11. undefined -> nitro:temp_id();
  12. I -> I
  13. end,
  14. nitro:wire( #event{type = click, postback = Postback, target = ID0,
  15. source = Record#input.source, delegate = Record#input.delegate} ),
  16. ID0
  17. end,
  18. List = [
  19. %% global
  20. {<<"accesskey">>, Record#input.accesskey},
  21. {<<"class">>, Record#input.class},
  22. {<<"contenteditable">>,
  23. case Record#input.contenteditable of
  24. true -> "true";
  25. false -> "false";
  26. _ -> undefined
  27. end},
  28. {<<"contextmenu">>, Record#input.contextmenu},
  29. {<<"dir">>,
  30. case Record#input.dir of
  31. "ltr" -> "ltr";
  32. "rtl" -> "rtl";
  33. "auto" -> "auto";
  34. _ -> undefined
  35. end},
  36. {<<"draggable">>,
  37. case Record#input.draggable of
  38. true -> "true";
  39. false -> "false";
  40. _ -> undefined
  41. end},
  42. {<<"dropzone">>, Record#input.dropzone},
  43. {<<"hidden">>,
  44. case Record#input.hidden of
  45. "hidden" -> "hidden";
  46. _ -> undefined
  47. end},
  48. {<<"id">>, Id},
  49. {<<"lang">>, Record#input.lang},
  50. {<<"spellcheck">>,
  51. case Record#input.spellcheck of
  52. true -> "true";
  53. false -> "false";
  54. _ -> undefined
  55. end},
  56. {<<"style">>, Record#input.style},
  57. {<<"tabindex">>, Record#input.tabindex},
  58. {<<"title">>, Record#input.title},
  59. {<<"translate">>,
  60. case Record#input.contenteditable of
  61. "yes" -> "yes";
  62. "no" -> "no";
  63. _ -> undefined
  64. end},
  65. %% spec
  66. {<<"autofocus">>, Record#input.autofocus},
  67. {<<"disabled">>,
  68. case Record#input.disabled of
  69. true -> "disabled";
  70. _ -> undefined
  71. end},
  72. {<<"name">>, Record#input.name},
  73. {<<"type">>, Record#input.type},
  74. {<<"accept">>, Record#input.accept},
  75. {<<"max">>, Record#input.max},
  76. {<<"placeholder">>, Record#input.placeholder},
  77. {<<"min">>, Record#input.min},
  78. {<<"multiple">>, Record#input.multiple},
  79. {<<"pattern">>, Record#input.pattern},
  80. {<<"value">>, Record#input.value},
  81. {<<"onkeypress">>, Record#input.onkeypress},
  82. {<<"onkeyup">>, Record#input.onkeyup},
  83. {<<"onkeydown">>, Record#input.onkeydown},
  84. {<<"onclick">>, Record#input.onclick},
  85. {<<"onchange">>, Record#input.onchange} | Record#input.data_fields
  86. ],
  87. wf_tags:emit_tag(<<"input">>, nitro:render(Record#input.body), List).