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

Elements don't get removed when Object<Array<String>> is reset #522

Closed
hkan opened this issue May 24, 2020 · 3 comments
Closed

Elements don't get removed when Object<Array<String>> is reset #522

hkan opened this issue May 24, 2020 · 3 comments

Comments

@hkan
Copy link

hkan commented May 24, 2020

Title feels weird, I didn't know how to explain it better and as short as possible.

Demo: https://codepen.io/hkanaktas/pen/JjYzqyq

Expected behavior

"fish are weird" should get removed when I click reset obj button.

Current behavior

"fish are weird" string is forgotten on the page. And more is added as the set fish button is clicked after resetting the object.

Extra info

My real use case here is: I have a validationErrors object. I set Laravel's error data (which is in Object<Array<String>> format) from 422 responses. When user resubmits the form, I simply reset them with validationErrors = {} before sending the request but the errors stay on page. But interesting enough that I don't get that repeating behavior in the demo pen.

Is this somehow my error? Maybe wrong key? Should I loop over the errors in another way?

@SimoTod
Copy link
Collaborator

SimoTod commented May 24, 2020

Your template content is invalid.
It has to be a single tag, you can just wrap everything inside a div.

<template x-if="...">
<div>...everything goes here...</div>
</template>

@hkan
Copy link
Author

hkan commented May 24, 2020

Ah, damn. I knew something was wrong with my code. Thanks Simone!

@hkan hkan closed this as completed May 24, 2020
@SimoTod
Copy link
Collaborator

SimoTod commented May 24, 2020

No worries. 👍

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

No branches or pull requests

2 participants