-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
jQuery Plugins #246
Comments
So the short answer is, you need two things: The elements that have should have attached behaviour need a <button data-reflex-permanent type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="Tooltip on top">
Hey I am tool-tipsy
</button> The second part is, you have to also listen to another event. So in the the application_controller.js set up the event afterReflex () {
const event = new Event('stimulus-reflex:load');
document.dispatchEvent(event)
} There are lifecycle events emitted by stimulus_reflex, like Then in some controller (in document.addEventListener('stimulus-reflex:load' => {
$('[data-toggle="tooltip"]').tooltip();
}) So this works but it is not very elegant, as you need to use permanent, and somehow can't use the build in lifecycle events (not sure what I am missing there) I hope this helps for the moment. I dug deeper, because personally I think we should be able to do this without |
@RolandStuder Thanks for your answer i've allready has |
@matedemorphy I really dived into this one. It is surprinsingly tricky, but mainly because the jQuery methods do weird things when attaching event handlers. So did you make sure the
import { Controller } from 'stimulus'
import StimulusReflex from 'stimulus_reflex'
export default class extends Controller {
connect () {
StimulusReflex.register(this)
}
afterReflex () {
const event = new Event('stimulus-reflex:load');
document.dispatchEvent(event)
console.log("stimulus-reflex:load dispatched")
}
} btw: There is an alternative to using |
@RolandStuder it's an implementation of tabulation demo with pagy gem, the thing is this |
it's normal that a |
i don't get it, according the docs https://docs.stimulusreflex.com/scoping#persisting-elements |
@matedemorphy do not listen to the terrible advice @RolandStuder gave to you (I am allowed to say this, as I wrote that advice) Adding a global event and listening is kind of bad. The stimulus way, is actually much more elegant. Just create a tooltip controller: import { Controller } from "stimulus"
import StimulusReflex from 'stimulus_reflex'
export default class extends Controller {
connect() {
$(this.element).tooltip()
this.element.setAttribute("data-reflex-permanent", true)
}
} and in you tooltip thing you make sure the tooltip element uses that controller: <button data-controller="tooltip" title="Tooltip on top"> The cool thing about this, is that is it actually agnostic to the implementation, so you can easily change the tooltip implementation without even changing the attributes. Just as a comment on your questions:
Connect get executed for every html element that has that controller, so yes, if you have 5 elements with tooltips, connect() will be executed for each html element.
This is not different to creating a new element with I think this issue should be closed. If you need more support I think it is better to ask in https://stimulus-reflex.discourse.group/ as this is not really an issue of StimulusReflex.
Yeah whatever is not set to data-permanent-reflex will be changed to its original state, before any |
@RolandStuder Thanks. |
@matedemorphy As I said forget about the And you are not giving any information so it is not possible to help you. If you want help you should put the same effort into your question as I put in my answer. Post you code, better yet, make the a repo accessible, state what you want, what you expect, what happens instead. Also read this: https://docs.stimulusreflex.com/lifecycle#client-side-reflex-callbacks and this https://github.com/RolandStuder/til/blob/master/stimulus-reflex/lifecycle-events-only-triggered-for-corresponding-controller.md |
@RolandStuder Sorry, and thanks for your help, but right now the class If i put |
Hi @matedemorphy, I hope you got your controllers working. I'm going to close this because it's more of a support concern than an issue with the library. If you are still looking for help on it, feel free to ask on Discord. |
Is there some additional configuration to achieve jQuery plugins works properly after a reflex is executed?. For example bootstrapSwitch.
document.addEventListener("turbolinks:load", () => { $('[data-toggle="tooltip"]').tooltip() $('[data-toggle="popover"]').popover() $("[type='checkbox']").bootstrapSwitch() })
Thanks
The text was updated successfully, but these errors were encountered: