The personal finance app for everyone (by everyone)
Ruby
<%# locals: (index:, categories:, merchants:, tags:, name: nil, amount: nil, category_id: nil, merchant_id: nil, tag_ids: [], removable: true) %>
<%# Styled builder fields and DS pickers, the same controls as the transaction form. %>
<div class="p-3 rounded-lg border border-secondary bg-container space-y-2" data-split-transaction-target="row">
<%= fields "split[splits][#{index}]", builder: StyledFormBuilder do |row| %>
<div class="flex flex-wrap md:flex-nowrap items-center gap-2">
<%= row.text_field :name,
value: name,
label: t("splits.new.name_label"),
placeholder: t("splits.new.name_placeholder"),
required: true,
autocomplete: "off",
container_class: "w-full md:flex-1 min-w-0",
data: { split_transaction_target: "nameInput" } %>
<%= row.number_field :amount,
value: amount,
label: t("splits.new.amount_label"),
placeholder: "0.00",
step: "0.01",
required: true,
autocomplete: "off",
container_class: "flex-1 md:flex-none md:w-32",
data: { split_transaction_target: "amountInput", action: "input->split-transaction#updateRemaining" } %>
<% if removable %>
<%= icon "x",
size: "sm",
as_button: true,
aria: { label: t("splits.new.remove_row") },
data: { action: "click->split-transaction#removeRow" } %>
<% else %>
<div class="w-8 shrink-0 hidden md:block"></div>
<% end %>
</div>
<%# Category and merchant share a row and tags get their own, like in the rule form, so the
category badge has room for real category names. %>
<div class="grid grid-cols-1 md:grid-cols-2 items-start gap-2">
<div class="category-select-container min-w-0">
<%= row.collection_select :category_id,
categories,
:id,
:display_name,
{ selected: category_id, include_blank: t("splits.new.uncategorized"), label: t("splits.new.category_label"),
variant: :badge, searchable: true, scoped_ids: true } %>
</div>
<div class="min-w-0">
<%= render DS::MerchantSelect.new(
form: row,
method: :merchant_id,
merchants: merchants,
selected_id: merchant_id,
label: t("splits.new.merchant_label"),
include_blank: t("splits.new.no_merchant")
) %>
</div>
<div class="min-w-0 md:col-span-2">
<%= render DS::TagSelect.new(
form: row,
tags: tags,
selected_ids: Array(tag_ids),
label: t("splits.new.tags_label"),
compact: true
) %>
</div>
</div>
<% end %>
</div>