element_comboLookupEdit.erl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -module(element_comboLookupEdit).
  2. -include_lib("nitro/include/comboLookupEdit.hrl").
  3. -include_lib("nitro/include/comboLookup.hrl").
  4. -include_lib("nitro/include/sortable_list.hrl").
  5. -include_lib("nitro/include/nitro.hrl").
  6. -include_lib("nitro/include/event.hrl").
  7. -export([
  8. render_element/1
  9. ]).
  10. render_element( #comboLookupEdit{id = Id, input = Input, disabled = Disabled,
  11. validation = Validation, form = Form,
  12. values = Values, multiple = Multiple}) ->
  13. ListId = form:atom([Id, "list"]),
  14. InputId = erlang:element(#element.id, Input),
  15. nitro:render(
  16. #panel{
  17. id = Id,
  18. validation = Validation,
  19. data_fields = [{<<"data-edit-input">>, <<"data-edit-input">>}],
  20. body = [
  21. #panel{
  22. style = "display:flex; position:relative; width:100%; justify-content:center;",
  23. body = [
  24. Input,
  25. case Multiple of
  26. true ->
  27. #link{class = [button, sgreen],
  28. style = "min-width:40px; text-align:center; height:fit-content; margin-left:5px;",
  29. onclick = nitro:js_escape("addSortableItemFrom('#" ++ ListId ++ "', '" ++ InputId ++ "')"),
  30. body = <<"+">> };
  31. false -> []
  32. end,
  33. case Disabled of
  34. true -> [];
  35. _ ->
  36. #panel{id = form:atom([InputId, "form"]),
  37. class = ['dropdown-content'],
  38. body = #panel{class = ['dropdown-item'], body = Form} }
  39. end
  40. ]},
  41. case Multiple of
  42. true ->
  43. #sortable_list{id = ListId, values = Values, closeable = true, disabled = Disabled};
  44. false -> []
  45. end
  46. ]}).