-
Notifications
You must be signed in to change notification settings - Fork 553
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
Adding event listeners before or after init? #536
Comments
You don't show your full code, what is your |
Thanks for the response, allow me to give a more reduced example: const builder = view.$el.find("#builder");
builder.on("afterAddGroup.queryBuilder", (event, group) => {
console.log("on after add group");
builder.queryBuilder("getRules");
})
.on("afterDeleteGroup.queryBuilder", () => {
console.log("on after delete group");
builder.queryBuilder("getRules");
})
.on("afterUpdateGroupCondition.queryBuilder afterUpdateRuleFilter.queryBuilder afterUpdateRuleOperator.queryBuilder afterUpdateRuleValue.queryBuilder", () => {
console.log("values updated");
builder.queryBuilder("getRules");
})
.on("afterMove.queryBuilder", (event, node) => {
console.log("after drag move");
builder.queryBuilder("getRules");
})
.on("afterInit.queryBuilder", () => {
console.log("after init");
builder.queryBuilder("getRules"); //I throw the error, but only because I run first, any of the getRules methods will
})
.queryBuilder({
rules: view.getDefaultRoot(),
allow_empty: true,
plugins: {
"not-group": null,
sortable: { icon: "icon-button icon-menu" }
},
display_empty_filter: false,
filters: view.filters,
icons: {
error: "icon-button bg-seagreen c-white icon-infoFilled"
},
templates: {
rule: templateRule(),
filterSelect: templateFilter(),
operatorSelect: templateOperator(),
group: templateGroup()
}
}); In this case, the first error comes from the
A step through of the stack trace error: https://giphy.com/gifs/3ohzgWmRhhtvRgoko0/fullscreen You can see querybuilder thinking there's no data and instantiating a new builder, which I suppose would have no filters, I suspect the issue is how/why that is occuring? If I were to comment out all the Just to re-iterate, a great library with great docs, I've got so far already! Thanks again for your help. |
I understand the behaviour but I really don't understand what you are trying to do, in |
Thanks again for the quick response, the issue isn't with Say if I comment out the I can even change all the As I mentioned before, from the stack trace it looks like it doesn't detect the jQuery-QueryBuilder/src/jquery.js Lines 32 to 34 in 2a23788
I'm not doing anything complicated with the selector, so I don't understand why this is the case? -- The use case is to have a SQL preview pane updating as frequently as possible when users change values in the builder, so on an event which I deem as a change to the builder (as there's no universal change event), I run |
Explanation : I will but the last few lines in an external method called avec complete creation. |
This makes sense, thanks again for the prompt replies, shall keep an eye out for 2.4.5 Then in theory you can chain all the events you want 👍 |
Thanks for this. To confirm, the issue I was facing wasn't specifically to do with the Does not seem to have access to the queryBuilder object via its selector and therefore does not have access to the options and filters when any of those event listeners fire, the selector returns empty so it creates another with no options which causes these errors. |
Hello all, I'm having a bit of a conundrum binding event listeners to querybuilder.
As per my code below, I'm adding the
.on()
event listeners chained before the init ofquerybuilder()
. This works in as much as all the events are detected correctly, includingafterInit
.The issue I'm having is that in some of the event listeners I'm trying to validate the query (on the fly validation) and if valid updating a SQL query preview. These all error with the following error. It's as if the querybuilder was initialised with no filters, when I know this is not the case, as that
view.filters
property is populated before the init, there's no async issues here, and before adding this on the fly validation, the builder was working perfectly.From going through the stack trace,
data
is returning undefined, so it seems a new instance of the builder is being initialised, a new instance which won't have filters etc. defined. I'm unsure why this is the case though, as I'm following the same pattern in the demo of$('selector').queryBuilder('method');
to run a method on an already initialised builder.jQuery-QueryBuilder/src/jquery.js
Lines 32 to 34 in 2a23788
I've tried chaining the
.on()
event listeners after thequeryBuilder()
but then half of them don't fire, for example bindingafterInit
after you've initialised the builder is pretty pointless.It's a pretty standard use-case, so I'm sure i'm not trying the impossible. Is there a suggested way I should be listening to these events?
Apologies if i'm doing something silly, I'm following the docs as closely as possible, I'm a bit stuck! A fantastic library and set of docs otherwise, I've got a lot done before hitting this issue!
Thanks in advance
The text was updated successfully, but these errors were encountered: