imacrayon / alpine-ajax

An Alpine.js plugin for building server-powered frontends.
https://alpine-ajax.js.org
MIT License
558 stars 11 forks source link

x-ref replace x-target #46

Closed ericxin1982 closed 8 months ago

ericxin1982 commented 8 months ago

Hi @imacrayon

Do you think you would have x-ref available to replace x-target in next version, since I may not have id for target element, but I would have x-ref for target element.

Thanks Eric Xin

ericxin1982 commented 8 months ago

And the indicator chapter, how you add the aira-busy class to target table, that is not clear enough. Would you please share?

imacrayon commented 8 months ago

Hi!

Do you think you would have x-ref available to replace x-target

That’s not likely to happen because we need a unique identifier on the page so that we know what content to merge inside an incoming request. x-ref is only unique per component, but id is required to be unique per page.

how you add the aira-busy class to target table

aria-busy is automatically added to a target when it is updating. You only need to write the CSS to make an indicator show when aria-busy is present.

ericxin1982 commented 8 months ago

That means aria-busy this css just prepared there, then indicator would take it if indicator tag is used, that is what you meant?

ericxin1982 commented 8 months ago

Then x-target can accept dynamic id? I mean the target id can be generated after it is being loaded into webpage.

imacrayon commented 8 months ago

That means aria-busy this css just prepared there, then indicator would take it if indicator tag is used, that is what you meant?

Yes, I think that's about right. There's not an indicator "tag" but you create the indicator by checking if aria-busy is present on a target using a CSS selector. I made a some quick demos that might help explain it better: https://codepen.io/imacrayon/pen/JjzGeMa

ericxin1982 commented 8 months ago

Then x-target can accept dynamic id? I mean the target id can be generated after it is being loaded into webpage. hi @imacrayon,

I have this concern, thanks. Please help me verify it.

imacrayon commented 8 months ago

Yes the ID in x-target can be dynamic you can include more than one ID too.

ericxin1982 commented 8 months ago

That is great, thanks for your help.

ericxin1982 commented 8 months ago

I saw all the examples, the whole alpine-ajax must be used within a form element? That is a must?

ericxin1982 commented 8 months ago

Can you give me more $ajax example, I try to understand it better, and think about how to use it properly.

ericxin1982 commented 8 months ago

Sorry, @imacrayon

I have one more question, how to add request header through $ajax to server, not the X-Alpine-Request I am talking about.

Thanks Eric Xin

imacrayon commented 8 months ago

No way to customize headers yet. That will probably be coming soon though.

ericxin1982 commented 8 months ago

Ok, then how about $ajax, we can use it in any element right?

imacrayon commented 8 months ago

Yeah, just like any other Alpine magic, you can use it within any event handler on any element.

ericxin1982 commented 8 months ago

That is excellent, good news to know.