Hi!
When i change partner which affect other fields:
Parameters: %{"_target" => ["invoice", "partner_id"], "invoice" => %{"currency_id" => "9425c106-1504-4ae5-a4f0-4dba1f10ae1f", "date" => "2023-03-06", "delivery_date" => "2023-03-06", "due_date" => "2023-03-06", "exchange_rate" => "1.0", "partner_id" => "2055bf2d-dd76-49be-ab93-b9837e184480", "payment_method" => "transfer", "payment_term" => "0"}}
changeset: #Ecto.Changeset<action: :validate, changes: %{}, errors: [],
data: #Invoicer.Invoice.Invoices.Invoice<>, valid?: true>
Brower console:
{
"3": {
"1": {
"0": {
"0": " method=\"post\" errors=\"\" id=\"invoice-form\" phx-change=\"validate\" phx-submit=\"save\"",
"1": "",
"2": "",
"3": {
"0": {
"2": {
"0": " phx-feedback-for=\"invoice[partner_id]\"",
"1": {
"0": " for=\"invoice-form_partner_id\"",
"1": {
"0": "Partner"
}
},
"2": " id=\"invoice-form_partner_id\"",
"3": " name=\"invoice[partner_id]\"",
"5": "",
"7": "<option value=\"\"></option><option selected value=\"2055bf2d-dd76-49be-ab93-b9837e184480\">Székely Kft.</option>",
"8": ""
},
"3": {
"0": {
"0": " phx-feedback-for=\"invoice[bank_account_id]\"",
"1": {
"0": " for=\"invoice-form_bank_account_id\"",
"1": {
"0": "Bank",
"s": [
"\n <span class=\"label-text\">\n ",
"\n </span>\n "
]
},
"s": [
"<label",
" class=\"label\">\n ",
"\n</label>"
]
},
"2": " id=\"invoice-form_bank_account_id\"",
"3": " name=\"invoice[bank_account_id]\"",
"4": "",
"5": "",
"6": "",
"7": "<option value=\"bc830162-9b9c-4ba5-a0e7-4a4a8dd414af\">KH Bank Zrt.</option>",
"8": "",
"s": [
"<div",
">\n ",
"\n <select",
"",
" class=\"select select-primary w-full p-2 focus:ring-0 focus:border-primary active:ring-0\"",
"",
">\n ",
"\n ",
"\n </select>\n ",
"\n</div>"
]
},
"s": [
"",
""
]
},
"4": {
"0": " phx-feedback-for=\"invoice[currency_id]\"",
"1": {
"0": " for=\"invoice-form_currency_id\"",
"1": {
"0": "Currency"
}
},
"2": " id=\"invoice-form_currency_id\"",
"3": " name=\"invoice[currency_id]\"",
"5": "",
"7": "<option selected value=\"9425c106-1504-4ae5-a4f0-4dba1f10ae1f\">Forint</option><option value=\"427e12b0-a581-4456-8a3c-4ba895d83f8a\">Euro</option>",
"8": ""
},
"5": {
"0": " phx-feedback-for=\"invoice[exchange_rate]\"",
"1": {
"0": " for=\"invoice-form_exchange_rate\"",
"1": {
"0": "Rate"
}
},
"2": " type=\"number\"",
"3": " name=\"invoice[exchange_rate]\"",
"4": " id=\"invoice-form_exchange_rate\"",
"5": " value=\"1\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": " step=\"any\"",
"8": ""
},
"6": {
"0": " phx-feedback-for=\"invoice[date]\"",
"1": {
"0": " for=\"invoice-form_date\"",
"1": {
"0": "Date"
}
},
"2": " type=\"date\"",
"3": " name=\"invoice[date]\"",
"4": " id=\"invoice-form_date\"",
"5": " value=\"2023-03-06\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": "",
"8": ""
},
"7": {
"0": " phx-feedback-for=\"invoice[delivery_date]\"",
"1": {
"0": " for=\"invoice-form_delivery_date\"",
"1": {
"0": "Delivery Date"
}
},
"2": " type=\"date\"",
"3": " name=\"invoice[delivery_date]\"",
"4": " id=\"invoice-form_delivery_date\"",
"5": " value=\"2023-03-06\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": "",
"8": ""
},
"8": {
"0": " phx-feedback-for=\"invoice[payment_term]\"",
"1": {
"0": " for=\"invoice-form_payment_term\"",
"1": {
"0": "Payment Term"
}
},
"2": " type=\"number\"",
"3": " name=\"invoice[payment_term]\"",
"4": " id=\"invoice-form_payment_term\"",
"5": " value=\"30\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": " min=\"0\" step=\"1\"",
"8": ""
},
"9": {
"0": " phx-feedback-for=\"invoice[due_date]\"",
"1": {
"0": " for=\"invoice-form_due_date\"",
"1": {
"0": "Due Date"
}
},
"2": " type=\"date\"",
"3": " name=\"invoice[due_date]\"",
"4": " id=\"invoice-form_due_date\"",
"5": " value=\"2023-04-05\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": "",
"8": ""
},
"10": {
"0": " phx-feedback-for=\"invoice[payment_method]\"",
"1": {
"0": " for=\"invoice-form_payment_method\"",
"1": {
"0": "Payment Method"
}
},
"2": " id=\"invoice-form_payment_method\"",
"3": " name=\"invoice[payment_method]\"",
"5": "",
"7": "<option selected value=\"transfer\">transfer</option><option value=\"credit\">credit</option><option value=\"card\">card</option><option value=\"cash\">cash</option><option value=\"voucher\">voucher</option>",
"8": ""
},
"11": ""
},
"1": ""
}
}
}
}
}
When i change date which doesn’t work:
Parameters: %{"_target" => ["invoice", "date"], "invoice" => %{"bank_account_id" => "bc830162-9b9c-4ba5-a0e7-4a4a8dd414af", "currency_id" => "9425c106-1504-4ae5-a4f0-4dba1f10ae1f", "date" => "2023-03-07", "delivery_date" => "2023-03-06", "due_date" => "2023-04-05", "exchange_rate" => "1", "partner_id" => "2055bf2d-dd76-49be-ab93-b9837e184480", "payment_method" => "transfer", "payment_term" => "30"}}
changeset: #Ecto.Changeset<
action: :validate,
changes: %{
bank_account_id: "bc830162-9b9c-4ba5-a0e7-4a4a8dd414af",
due_date: ~D[2023-04-05],
exchange_rate: 1.0
},
errors: [],
data: #Invoicer.Invoice.Invoices.Invoice<>,
valid?: true
Browser console:
{
"3": {
"1": {
"0": {
"0": " method=\"post\" errors=\"\" id=\"invoice-form\" phx-change=\"validate\" phx-submit=\"save\"",
"1": "",
"2": "",
"3": {
"0": {
"2": {
"0": " phx-feedback-for=\"invoice[partner_id]\"",
"1": {
"0": " for=\"invoice-form_partner_id\"",
"1": {
"0": "Partner"
}
},
"2": " id=\"invoice-form_partner_id\"",
"3": " name=\"invoice[partner_id]\"",
"5": "",
"7": "<option selected value=\"\"></option><option value=\"2055bf2d-dd76-49be-ab93-b9837e184480\">Székely Kft.</option>",
"8": {
"d": [
[
{
"0": {
"0": {
"0": " aria-hidden=\"true\" class=\"mt-0.5 h-5 w-5 flex-none fill-rose-500\" fill=\"currentColor\" viewBox=\"0 0 20 20\"",
"1": {
"0": "<path fill-rule=\"evenodd\" d=\"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z\" clip-rule=\"evenodd\"/>",
"s": 0
},
"s": 1
},
"s": 2
},
"1": {
"0": "can't be blank",
"s": 3
},
"s": 4
}
]
],
"p": {
"0": [
"",
""
],
"1": [
"<svg xmlns=\"http://www.w3.org/2000/svg\"",
">\n ",
"\n</svg>"
],
"2": [
"",
""
],
"3": [
"",
""
],
"4": [
"<p class=\"phx-no-feedback:hidden mt-3 flex gap-3 text-sm leading-6 text-rose-600\">\n ",
"\n ",
"\n</p>"
]
},
"s": [
"",
""
]
}
},
"3": "",
"4": {
"0": " phx-feedback-for=\"invoice[currency_id]\"",
"1": {
"0": " for=\"invoice-form_currency_id\"",
"1": {
"0": "Currency"
}
},
"2": " id=\"invoice-form_currency_id\"",
"3": " name=\"invoice[currency_id]\"",
"5": "",
"7": "<option selected value=\"9425c106-1504-4ae5-a4f0-4dba1f10ae1f\">Forint</option><option value=\"427e12b0-a581-4456-8a3c-4ba895d83f8a\">Euro</option>",
"8": ""
},
"5": {
"0": " phx-feedback-for=\"invoice[exchange_rate]\"",
"1": {
"0": " for=\"invoice-form_exchange_rate\"",
"1": {
"0": "Rate"
}
},
"2": " type=\"number\"",
"3": " name=\"invoice[exchange_rate]\"",
"4": " id=\"invoice-form_exchange_rate\"",
"5": " value=\"1.0\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": " step=\"any\"",
"8": ""
},
"6": {
"0": " phx-feedback-for=\"invoice[date]\"",
"1": {
"0": " for=\"invoice-form_date\"",
"1": {
"0": "Date"
}
},
"2": " type=\"date\"",
"3": " name=\"invoice[date]\"",
"4": " id=\"invoice-form_date\"",
"5": " value=\"2023-03-07\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": "",
"8": ""
},
"7": {
"0": " phx-feedback-for=\"invoice[delivery_date]\"",
"1": {
"0": " for=\"invoice-form_delivery_date\"",
"1": {
"0": "Delivery Date"
}
},
"2": " type=\"date\"",
"3": " name=\"invoice[delivery_date]\"",
"4": " id=\"invoice-form_delivery_date\"",
"5": " value=\"2023-03-06\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": "",
"8": ""
},
"8": {
"0": " phx-feedback-for=\"invoice[payment_term]\"",
"1": {
"0": " for=\"invoice-form_payment_term\"",
"1": {
"0": "Payment Term"
}
},
"2": " type=\"number\"",
"3": " name=\"invoice[payment_term]\"",
"4": " id=\"invoice-form_payment_term\"",
"5": " value=\"0\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": " min=\"0\" step=\"1\"",
"8": ""
},
"9": {
"0": " phx-feedback-for=\"invoice[due_date]\"",
"1": {
"0": " for=\"invoice-form_due_date\"",
"1": {
"0": "Due Date"
}
},
"2": " type=\"date\"",
"3": " name=\"invoice[due_date]\"",
"4": " id=\"invoice-form_due_date\"",
"5": " value=\"2023-03-06\"",
"6": "input-bordered input-primary focus:border-primary input w-full focus:ring-0",
"7": "",
"8": ""
},
"10": {
"0": " phx-feedback-for=\"invoice[payment_method]\"",
"1": {
"0": " for=\"invoice-form_payment_method\"",
"1": {
"0": "Payment Method"
}
},
"2": " id=\"invoice-form_payment_method\"",
"3": " name=\"invoice[payment_method]\"",
"5": "",
"7": "<option selected value=\"transfer\">transfer</option><option value=\"credit\">credit</option><option value=\"card\">card</option><option value=\"cash\">cash</option><option value=\"voucher\">voucher</option>",
"8": ""
},
"11": ""
},
"1": ""
}
}
}
}
}
Which may also be interesting is i don’t assign starter invoice datas in mount, but in apply action, because i use this form inside a liveview, and later i would like to use this liveview as edit mode:
defp apply_action(socket, :new, _params) do
today = Date.utc_today()
invoice = %Invoice{
name: "Draft",
date: today,
delivery_date: today,
due_date: today,
notes: "",
state: "new",
payment_term: 0,
invoice_lines: []
}
changeset =
invoice
|> Invoices.change_invoice(%{})
|> Ecto.Changeset.put_assoc(:invoice_lines, invoice.invoice_lines)
socket
|> assign(:page_title, "New Invoice")
|> assign(:invoice, invoice)
|> assign(:changeset, changeset)
end