Git Product home page Git Product logo

Comments (7)

ericxin1982 avatar ericxin1982 commented on May 28, 2024 1

Thanks so much!
I got the point now.

from alpine-ajax.

imacrayon avatar imacrayon commented on May 28, 2024

Hi Eric, the Alpine AJAX example uses a native HTML Dialog, no extra library is required.

There are a few ways you could add a class with Alpine. If the modal element already has an id I would use @ajax:before="document.getElementById('modal').classList.add('uk-open')" but you could also use x-ref to select the modal or :class to add the modal class.

from alpine-ajax.

ericxin1982 avatar ericxin1982 commented on May 28, 2024

Hi @imacrayon

I prefer the modal is got by alpine ajax, and then add the top element downloaded by alpine ajax has 'uk-open' class, so I prefer to use alpine ajax event to add class, not alpine event to add class.

Do you think it is possible?
The htmx && Hyperscript that case is using Hyperscript event to add class, after downloaded.

Thanks
Eric Xin

from alpine-ajax.

imacrayon avatar imacrayon commented on May 28, 2024

The htmx && Hyperscript that case is using Hyperscript event to add class, after downloaded.

You can listen for the ajax:after event instead of ajax:before to set your class after the download:

@ajax:after="document.getElementById('modal').classList.add('uk-open')"

from alpine-ajax.

ericxin1982 avatar ericxin1982 commented on May 28, 2024

Hi @imacrayon

This @Ajax:after is alpine.ajax has, or alpine has?

Thanks
Eric Xin

from alpine-ajax.

ericxin1982 avatar ericxin1982 commented on May 28, 2024

Hi @imacrayon

You know @Ajax:after then I need to extract the html string from response, then I need to place into the right element, I may need to wait for a bit, is there a wait function or something else I can use to delay 10 or 20ms after @Ajax:after?

Thanks
Eric Xin

from alpine-ajax.

imacrayon avatar imacrayon commented on May 28, 2024

This @Ajax:after is alpine.ajax has, or alpine has?

It's an event fired by Alpine AJAX, you can see them all here: https://alpine-ajax.js.org/reference/#ajax-events

I prefer the modal is got by alpine ajax

Sorry, i didn't understand this at first but, I get what you are saying now. I put together an example here: https://codepen.io/imacrayon/pen/KKrgmgZ

Instead of selecting the modal after the response, I would add x-init on the modal, the x-init will automatically run when the modal is added to the page. (see line 9 in the CodePen)

from alpine-ajax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.