bennydreamtech23

bennydreamtech23

please i would like to understand how to implement cast_assoc form for has many relationship using inputs_for for the nested relationship but currently only working for has_one and not implementing for has_many relatiosnhip, when it comes to has many only the main field showing not the associated field:


This is the html aspect of my code:

  <%= form_for @payment_changeset, "#", [phx_submit: :create_payment, phx_change: :validate_payment_entry, phx_target: @myself, id: "capture_account_info"], fn f -> %>
          <div class="border border-gray-300 rounded-lg p-6 bg-white shadow-md">
            <div class="manual-entry-css">
              <div class="flex md:flex-row flex-col items-center justify-between gap-4">
                <%= inputs_for f, :beneficiaries, fn b_changeset -> %>
                  <div class="py-3">
                    <%= select(
                      b_changeset,
                      :bank_id,
                      Enum.map(@bank_names, &{&1.bank_name, &1.id}),
                      required: true,
                      class: "focus:outline-0 px-4 py-2 rounded-l-md w-full border form-control",
                      phx_update: :ignore
                    ) %>
                    <%= hidden_input(b_changeset, :bank_location, value: "local") %>
                  </div>

                  <div class="py-3">
                    <%= text_input(b_changeset, :account_number,
                      required: true,
                      class: "w-full form-control",
                      placeholder: " Account Number"
                    ) %>
                    <p class="block ">
                      <%= error_tag(b_changeset, :account_number) %>
                    </p>
                  </div>
                <% end %>
                <div class="py-3">
                  <%= text_input(
                    f,
                    :balance,
                    class: "w-full form-control",
                    placeholder: "Amount",
                    required: true
                  ) %>
                </div>
              </div>
            </div>
            <div class="flex items-end justify-end lg:mt-2 mt-4">
              <button phx-target={@myself} type="submit" class="btn-primary rounded-sm">
                Add
              </button>
            </div>
          </div>
        <% end %>
      </div>
    <% end %>

please i need help with fixing this problem

First Post!

bennydreamtech23

bennydreamtech23 OP

Please am stll facing the issue

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hi @bennydreamtech23 can you provide more information? What is the main schema you are operating with? What is the has_many relationship you want to create? What have you tried so far?

LostKobrakai

LostKobrakai

Multiple options. I’d suggest the first one, unless that doesn’t work for some reason in your usecase:

The second one can still be educational nontheless.

bennydreamtech23

bennydreamtech23 OP

Thank you, i will check them out and give feedback once i am done

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews