element_comboLookupVec.erl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. -module(element_comboLookupVec).
  2. -include_lib("nitro/include/comboLookupVec.hrl").
  3. -include_lib("nitro/include/sortable_list.hrl").
  4. -include_lib("nitro/include/nitro.hrl").
  5. -include_lib("nitro/include/event.hrl").
  6. -export([
  7. render_element/1
  8. ]).
  9. render_element( #comboLookupVec{id = Id, input = Input, disabled = Disabled, validation = Validation, values = Values} ) ->
  10. ListId = form:atom([Id, "list"]),
  11. nitro:render(
  12. #panel{
  13. id = Id,
  14. validation = Validation,
  15. data_fields = [{<<"data-vector-input">>, <<"data-vector-input">>}],
  16. body = [
  17. #panel{
  18. style = "display: flex; width: 100%; justify-content: center;",
  19. body =
  20. case Disabled of
  21. true -> [];
  22. _ ->
  23. [ Input,
  24. #link{
  25. class = [button, sgreen],
  26. style = "min-width: 40px; text-align: center; height: fit-content; margin-left: 5px;",
  27. onclick = nitro:jse("addSortableItemFrom('#" ++ ListId ++ "', '" ++ erlang:element(#element.id, Input) ++ "')"),
  28. body = <<"+">>}
  29. ]
  30. end
  31. },
  32. %% TODO: Add validation for each list_item and/or "+" button
  33. %% TODO?: Maybe show message "Empty list" when Values == []
  34. #sortable_list{id = ListId, values = Values, closeable = true, disabled = Disabled}
  35. ]}).