ekwoka / alpine-plugins

Mono repo for various Alpine plugin packages
8 stars 2 forks source link

X-ajax request on event (or handle 'empty string') #2

Closed josh-tt closed 1 year ago

josh-tt commented 1 year ago

Id like a way to better control when x-ajax does it's request. If there is some easy way to make x-ajax wait for an event before requesting the url or to handle empty string graciously would be nice.

For example: As it is currently, x-ajax seems to require a url and fetches it immediately. In some cases, you don't want this to happen, but using an empty string seems to cause errors.

I've tried to putting my x-ajax in a template with x-if, but doing so seems to result in repeat fetches.
For example:

<template x-if="open">
<div
      x-init="myUrl='http...'"
      x-ajax.query.article.replace="myUrl"
  >

Thought it might work, but each 'open' then gives me a duplicate. I'm sure there is a clever way around this with alpine, though perhaps it's something that could be easily addressed by handling 'empty string' and ignoring. This way you could do: x-ajax.query.article.replace="open ? 'myUrl' : ''"

ekwoka commented 1 year ago

Resolved in 0.3.0