Open vraravam opened 7 years ago
Looks like a valid bug
Same issue here. In my case, it is required that a DisciplineTitle
have an associated discipline_id
field, but this is missing when the form is submitted, and the changeset error is thrown indicating that discipline_id
must not be blank :(
I should also add that this error occurs regardless of whether :discipline_id
is required in the changeset or not.
# This line doesn't need not exist in order to receive the error
|> validate_required(~w(discipline_id)a)
Error:
Ecto.InvalidChangesetError at POST /admin/disciplines could not perform insert because changeset is invalid.
* Changeset changes
%{name: "test"}
* Changeset params
%{"_destroy" => "0", "name" => "test"}
* Changeset errors
[{"discipline[discipline_titles_attributes][0][discipline_id]", {"can't be blank", []}}]
models/discipline.ex
schema "disciplines" do
field :name, :string
has_many :discipline_titles, App.DisciplineTitle
end
models/discipline_title.ex
schema "discipline_titles" do
field :name, :string
belongs_to :discipline, App.Discipline
timestamps()
end
admin/discipline.ex
form discipline do
inputs do
input discipline, :name
end
inputs "Titles" do
has_many discipline, :discipline_titles, fn(t) ->
input t, :name
end
end
end
I should note that upon form submission, both the Discipline and the DisciplineTitle are both added to the database, their relationship is working as expected, and they are accessible via the ExAdmin CMS despite the fact that a 500 error is given.
Adding a new discipline and adding a discipline title to go along
The form is submitted and an error is received
Despite the error, the Discipline was still created
Despite the error, the DisciplineTitle was still created
Note the correct relationship is in place
I'm trying out the contact_demo repo as the example of this package. In the contact edit screen, when I click on the "Add New Phone number" button (for has_many in a nested form), and then I do not enter any phone number in the text box, but submit the form, this is the error that I get