Comments (5)
Ah, I was able to track down the problem.
It's some browser DOM weirdness and some unsafe programming on my part. Since your submit button is named id
. In JavaScript, document.querySelector('form').id
will actually reference the <button>
element inside the form instead of the id
attribute on the form 😩. I should be using document.querySelector('form').getAttribute('id')
instead to prevent that name conflict.
I'll try to get a patch out really soon, but in the meantime if you change that button name to something like name="comment_id"
you should have things working.
from alpine-ajax.
Thank you for the thorough details!
from alpine-ajax.
Hi, so there's something a bit off with that rendered HTML:
<form id="like" x-init="" x-target="button" method="post" action="/comments/1/like">
x-target
can be either empty (x-target
) or x-target="like"
but,x-target="button"
is the cause of the error. The template code you shared appears fine, I'm not sure where the value of button
would be coming from.
from alpine-ajax.
I think i copy pasted the html from my browser incorrectly. The x-target is empty and not button. Sorry for the confusion.
Here is the actual html
<html lang="en" class=" dnvyzo idc0_350">
<head><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script defer="" src="https://cdn.jsdelivr.net/npm/@imacrayon/[email protected]/dist/cdn.min.js"></script>
<script defer="" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cdn.min.js"></script>
</head>
<body>
<form id="like" x-init="" x-target="" method="post" action="/comments/1/like">
<button name="id" value="1">Like</button>
</form>
</body>
</html>
Based on your answer i am assuming x-target="" should be x-target instead for it to target itself. But i'm not sure if a can configre my html render to not parse it like this
Here is a picture from the browser:
from alpine-ajax.
Amazing! You're so fast. Thank you very much.
Quite a hilarious bug. Good thing you found it.
This also explains why removing name="id" and value="1" from my buttons fixed the issue
from alpine-ajax.
Related Issues (20)
- x-ref replace x-target HOT 15
- Bug when target is a tr
- TypeError in latest version HOT 2
- Able to set `enctype` to application/x-www-form-urlencoded HOT 1
- Add support for `autofocus`
- `MissingIdError` error thrown when using `x-target.replace` without an ID HOT 2
- Calling $ajax from code outside of Alpine.js HOT 5
- Use ajax:success to preload assets (js) HOT 3
- Could not find a declaration file for module '@imacrayon/alpine-ajax' HOT 3
- Any way to make incoming html replace the innerHTML of target instead of the whole target? HOT 3
- SSE and websockets support HOT 4
- Using x-morph, new Alpine components don't initialize HOT 5
- Apply different merge strategy per target HOT 4
- Polling support? HOT 2
- Dynamically assigning a value for x-target not working, but works if assigning it statically. HOT 4
- Filterable content + infinite scroll: how to set x-merge attribute HOT 3
- v.0.6.0 broke the usual x-target behavior HOT 8
- x-target response code modifiers HOT 2
- Question: Fetch and headers HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alpine-ajax.