joaquinalcerro
Hi guys,
Following up on this github issue where @grych has been kindly helping:
https://github.com/grych/drab/issues/181
I have been trying to get this right but still unable to make it work.
I have the basic controller, commander setup but with nested partials as follows:
Controller renders → new.html.drab template
new.html.drab template renders → form.html.drab template
the form.html.drab template renders → _invoices.html.drab template
invoices.html.drab template renders → _invoice_details.html.drab template
I am setting a drab-change event handler in a input checkbox in the last partial invoice_details.
This event handler triggers a update to a assign (po_grantotal) and this assign is located in the form.html.drab template
This are the form.html.drab template assigns:
iex(6)> socket |> assigns("form.html")
[:action, :changeset, :conn, :currency_us, :invoices, :parent, :po_grantotal]
This is a peek at that assign:
iex(7)> socket |> peek("form.html", :po_grantotal)
{:ok, 0}
So my poke call is as follows:
poke socket, "form.html", po_grantotal: 1000
With this setup I get the following error:
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil. This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range,
Ecto.Adapters.SQL.Stream, File.Stream, Floki.HTMLTree, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Postgrex.Stream, Range, Scrivener.Page
, Stream, Timex.Interval
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:141: Enumerable.reduce/3
(elixir) lib/enum.ex:1919: Enum.map/2
(epr) lib/epr_web/templates/payment_order/form.html.drab:76: anonymous fn/2 in EprWeb.PaymentOrderView."form.html"/1
(phoenix_html) lib/phoenix_html/form.ex:288: Phoenix.HTML.Form.form_for/4
(epr) lib/epr_web/templates/payment_order/form.html.drab:1: EprWeb.PaymentOrderView."form.html"/1
(phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/view.ex:339: Phoenix.View.render_to_string/3
(drab) lib/drab/live.ex:683: Drab.Live.rerender_template/4
(drab) lib/drab/live.ex:638: Drab.Live.process_poke/9
Is this a correct setup? What am I doing wrong?
Thanks in advance for your help.
Best regards,
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 10 Posts
grych
Could you pls try
Something becomes nil, I am worried that it might be a changeset..
joaquinalcerro
This is the peek changeset result:
I also peek all the assigns for this form and none where nil.
This are all the assigns:
grych
Is the
form_foronly enumerable you did use in form.html? Maybe we are checking the wrong place.joaquinalcerro
Yes, I use the form_for in the “form.html” template.
I am going to try something else with the nested templates.
grych
It looks like a bug, but I can’t reproduce it.
Could you please inspect the @changeset and @action in form.html?
Also, could you check from the JS console, if the changeset exists in the
__drab.assignsobject?joaquinalcerro
This is the result:
form.html.drab
result printed out in the browser page
This is the Google Chrome Console output for _drab
Thanks again for the help.
grych
Can you also do
IO.inspect(@changeset)(beforeform_for) in form.html and show the result of it when you are trying to update the page withpokeand it fails?joaquinalcerro
This is the form.html.drab code:
This is the result when I click the drab element to call de poke function:
iex(25)> is the moment when the page first loads
iex(27)> is the moment when the poke function was called
grych
I have no idea what can be wrong then. All looks good, the data given to
form_forlooks exactly the same, I have no idea where thenilmay come fromjoaquinalcerro
@grych,
So I finally identified the problem. Turns out that I use a Enum function inside the form.html.drab. This is the code:
Please note that is use assigns[:bank_accounts] instead of @bank_accounts.
The first time this form.html.drab is rendered, this assign is there because I added it in the controller and the form renders correctly with the bank_accounts information:
But when I check the drab assigns, it is not there:
And when you poke the assign and re-render the form, the assign[:bank_accounts] is nil.
So simple solution was to change the assign[:bank_accounts] to @bank_accounts as I should and now it all works fine.
Thanks for your help.
Best regards,