How to change rule inputs
Hi, I'm trying to change the input fields that is being showed for DateTime field. to accomplish this I used the below code
on('afterCreateRuleInput.queryBuilder', function (e, rule) {
var ruleValueContainer = rule.$el.find('.rule-value-container');
var inputs = rule.$el.find('.rule-value-container [name*=_value_]');
var controlnames = [];
for (var i = 0; i < inputs.length; i++) {
controlnames.push($(inputs[i]).attr("name"));
}
var _lastPeriodContolUpdated = function () {
if (!this._updating_input) {
rule._updating_value = true;
rule.value = $(".TheControl").queryBuilder("getRuleInputValue", rule);
rule._updating_value = false;
}
};
if (rule.operator.type == "MySpecialType"){
$(ruleValueContainer).empty();
var ddl = $("<input name='" + controlnames[0] + "' class='form-control' />");
$(ruleValueContainer).append(ddl);
$(ddl).on('change', function () {
_lastPeriodContolUpdated();
});
}
}
The code is working just fine for me when I'm defining the rule. but it i snot working for the following cases:
- When I'm reloading the filters/data again to the control, using Json.
- when user changing the Operator with same number of input controls, the above event is not being triggered.
Can you please let me know if I'm doing something wrong? or I need to change my code in different way?
Thanks in advance
I don't understand what you are doing here, your destroy the original inputs and re-recreate the same thing ? Why ?
If you want to customize the input, use the input filter property as a function.
Yes this is exactly what I'm trying to do.. basically based on operator selected by user, I need to have different input fields based on the operator.
can I use the input filter property while still using the built-in operator's input fields? if yes, I would appreciating pointing me to the way or doc.
Unfortunately no, i think your need is similar to #284 but I don't have time to implement it.
You could try to listen the afterUpdateRuleOperator.queryBuilder event with similar code (be aware that on first load the operator is changed before building the input).
Thanks for your prompted response. yes I'm facing the same case as #284. I tried to implement listener for afterUpdateRuleOperator.queryBuilder event but that didn't solve the problem.
Is there an event that is being fired after the rule is bind-ed to UI? maybe I can utilize that event in order to manipulate the rule's input as I need. Thanks again!
The full list of events is in the doc http://querybuilder.js.org/api/list_event.html
I am updating the value of the textfield through jquery but when i run queryBuilder('getRules') it is empty. May i know if there are still some functions that need to trigger for the rules to be not empty?