element_search.erl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. -module(element_search).
  2. %%-author('Vladimir Galunshchikov').
  3. -include_lib("nitro/include/nitro.hrl").
  4. -include_lib("nitro/include/event.hrl").
  5. -export([
  6. render_element/1
  7. ]).
  8. render_element(Record) when Record#search.show_if == false -> [<<>>];
  9. render_element(Record) ->
  10. Id = case Record#search.postback of
  11. [] -> Record#search.id;
  12. Postback ->
  13. ID0 = case Record#search.id of
  14. [] -> nitro:temp_id();
  15. I -> I
  16. end,
  17. nitro:wire( #event{type = click, postback = Postback, target = ID0,
  18. source = Record#search.source,
  19. delegate = Record#search.delegate} ),
  20. ID0
  21. end,
  22. List = [
  23. %% global
  24. {<<"accesskey">>, Record#search.accesskey},
  25. {<<"class">>, Record#search.class},
  26. {<<"contenteditable">>,
  27. case Record#search.contenteditable of
  28. true -> "true";
  29. false -> "false";
  30. _ -> []
  31. end},
  32. {<<"contextmenu">>, Record#search.contextmenu},
  33. {<<"dir">>,
  34. case Record#search.dir of
  35. ltr -> "ltr";
  36. rtl -> "rtl";
  37. auto -> "auto";
  38. _ -> []
  39. end},
  40. {<<"draggable">>,
  41. case Record#search.draggable of
  42. true -> "true";
  43. false -> "false";
  44. _ -> []
  45. end},
  46. {<<"dropzone">>, Record#search.dropzone},
  47. {<<"hidden">>,
  48. case Record#search.hidden of
  49. true -> "hidden";
  50. _ -> []
  51. end},
  52. {<<"id">>, Id},
  53. {<<"lang">>, Record#search.lang},
  54. {<<"spellcheck">>,
  55. case Record#search.spellcheck of
  56. true -> "true";
  57. false -> "false";
  58. _ -> []
  59. end},
  60. {<<"style">>, Record#search.style},
  61. {<<"tabindex">>, Record#search.tabindex},
  62. {<<"title">>, Record#search.title},
  63. {<<"translate">>,
  64. case Record#search.contenteditable of
  65. true -> "yes";
  66. false -> "no";
  67. _ -> []
  68. end},
  69. %% spec
  70. {<<"autocomplete">>,
  71. case Record#search.autocomplete of
  72. true -> "on";
  73. false -> "off";
  74. _ -> []
  75. end},
  76. {<<"autofocus">>,
  77. case Record#search.autofocus of
  78. true -> "autofocus";
  79. _ -> []
  80. end},
  81. {<<"dirname">>, Record#search.dirname},
  82. {<<"disabled">>,
  83. case Record#search.disabled of
  84. true -> "disabled";
  85. _ -> []
  86. end},
  87. {<<"form">>, Record#search.form},
  88. {<<"list">>, Record#search.list},
  89. {<<"maxlength">>, Record#search.maxlength},
  90. {<<"name">>, Record#search.name},
  91. {<<"pattern">>, Record#search.pattern},
  92. {<<"placeholder">>, Record#search.placeholder},
  93. {<<"readonly">>,
  94. case Record#search.readonly of
  95. true -> "readonly";
  96. _ -> []
  97. end},
  98. {<<"required">>,
  99. case Record#search.required of
  100. true -> "required";
  101. _ -> []
  102. end},
  103. {<<"size">>, Record#search.size},
  104. {<<"type">>, <<"search">>},
  105. {<<"value">>, Record#search.value} | Record#search.data_fields
  106. ],
  107. wf_tags:emit_tag(<<"input">>, nitro:render(Record#search.body), List).