Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field does not save when used from inline form #92

Open
miagg opened this issue Feb 9, 2023 · 7 comments
Open

Field does not save when used from inline form #92

miagg opened this issue Feb 9, 2023 · 7 comments

Comments

@miagg
Copy link

miagg commented Feb 9, 2023

In Nova4 Inline HasOne Creation has been introduced that allows to create/update a HasOne/MorphOne relation from the parent resource.

However it seems MorphOne it is not compatible with Nova-Translatable.
I can see the field and the language selectors but when I update the model, the values do not get stored.

bug.mov

There are no errors on laravel.log or browser console.

Also, validation does work but with no visual indicator on the field or error message.

If I edit the relation outside the parent resource, everything works as expected.

@marcelosantos89
Copy link

marcelosantos89 commented Feb 10, 2023

Same problem here can't figure out what's wrong

This is not a fix but a turnaround

            MorphOne::make('Seo')
                ->hideWhenUpdating()
                ->hideWhenCreating(),

The fields don't save when created inline, still we'll be able to develop until a solution is found

@jaap
Copy link

jaap commented Mar 6, 2023

Tried debugging this issue, but no cigar unfortunately.

I think the problems lies in the Vue component.

When editing the Model from it's own resource (not trough the relation) you can see the request having the language attributes within the field.

CleanShot 2023-03-06 at 08h49

When doing the same update, but now trough the parent model and by using the Morph relationship you can see the attributes are missing from the request.

CleanShot 2023-03-06 at 08h54

Hopefully these steps help a bit in reproducing the issue. I'll give debugging the Vue components a shot. Will update here on any findings.

@jaap
Copy link

jaap commented Mar 6, 2023

Did some more debugging and found a difference when the fill() method is called from a regular Model vs a relation

When console logging the formData on line 96

fill(formData) {
try {
if (this.isFlexible && this.isFile)
return alert('Sorry, nova-translatable File and Image fields inside Flexible currently do not work.');
const data = {};
const originalAttribute = this.currentField.translatable.original_attribute;
for (const locale of this.locales) {
const tempFormData = new FormData();
const field = this.fields[locale.key];
if (field.fill) field.fill(tempFormData);
const formDataKeys = Array.from(tempFormData.keys());
for (const rawKey of formDataKeys) {
const [key, value] = this.getKeyAndValue(rawKey, locale, tempFormData);
if ((this.isFlexible && key.endsWith(originalAttribute + `[${locale.key}]`)) || this.isSimpleRepeatable) {
if (this.isKeyAnArray(rawKey)) {
if (!data[locale.key]) data[locale.key] = [];
data[locale.key].push(value);
} else {
data[locale.key] = value;
}
} else {
formData.append(key, value);
}
}
}
if (this.isFlexible || this.isSimpleRepeatable) formData.append(originalAttribute, JSON.stringify(data));
return;
} catch (e) {
console.error(e);
}
},

When called from a regular model:
CleanShot 2023-03-06 at 09h53

When called from trough the Morph relationship:
CleanShot 2023-03-06 at 09h56

It seems to me that that somehow within the fill() method there's a need to apply some sort of logic on determining if the update is coming trough a relation.

jaap added a commit to jaap/nova-translatable that referenced this issue Mar 6, 2023
@eugenl1nde
Copy link

Hey @miagg!

Could you share more details so we could reproduce your issue?
Currently tested it on nova 4.22.2 and the new hasOne relation was created with the translation.

@miagg
Copy link
Author

miagg commented Mar 20, 2023

Hi @eugenl1nde,
Sorry, I forgot to mention that the relation field is a MorphOne field instead of HasOne.
I tried again with Nova 4.22.2 just to be sure and it does not work. See video for more details.

Also, I tried #94 and it seems to do the job.

@miagg
Copy link
Author

miagg commented Apr 1, 2023

Any progress on this?
I noticed that validation does not kick either, so I had to revert to hiding the MorphOne field until it is officially supported by the package.

@Tarpsvo
Copy link
Collaborator

Tarpsvo commented Jun 30, 2023

I merged the solution PR-ed by @jaap and it should work a bit better now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants