Open mjraval opened 4 years ago
Please create an jsfiddle or similar
@mistic100 , Thanks for the Quick response. Sorry, took a while to put that in place. Edited the Comment and added link to jsFiddle.
Hello @mjraval ,
In order to set predefined value you should use the "valueSetter".
valueSetter: function (rule) { setRuleValue(rule); }
So your filter --> input will be,
{
id: "3MS1",
label: "3M Sales S1",
type: "integer",
input: function ( rule, name ) {
return input_creator_fieldComparison( rule, name );
},
valueGetter: function ( rule ) {
return valueGatter_fieldComparison( rule );
},
valueSetter: function ( rule )
{
setRuleValue(rule);
}
}
function setRuleValue(rule)
{
**// You can customize this method based on your requirements.**
if (rule.operator.optgroup !== null)
{
rule.$el.find('.rule-value-container select:first').val(rule.value);
}
else
{
var valueContainer = rule.$el.find('.rule-value-container');
if (rule.operator.nb_inputs <= 1)
{
var input = valueContainer.find('input');
if (input.length === 0)
{
input = valueContainer.find('select:not(:first)');
}
input.val(rule.value);
}
else
{
var index = 0;
valueContainer.find('input').each(function ()
{
$(this).val(rule.value[index]);
index++;
});
}
}
}
Hope this will help...
Did you end up being able to solve this? I am encountering this as well.
In one case, I am trying to access rule.value on a successful ajax request, in this situation rule.value works. But if I try to call it before that ajax call, it is undefined.
The Problem:
Accessing the
value
in theRule
Object always returnsundefined
. Inconsole.log(rule)
, it can be seen that thevalue
property of the rule object has a value. Tried to access it byrule.value
andrule["value"]
. Both yieldingundefined
alwaysjsFiddle : Link
Larger Picture
I am able to show, custom operators, and show the input field as
select dropdown
ornumber input
according to the operator selected. Its just that when loading pre-defined rules, not able to access value.Solutions to be achieved
I have custom Code to Deal with Comparing 2 fields of Database. On selecting a specific type of operations , ie the once in
FieldsOps
group and name ending with an_
, the input would be a dropdown. And also pre populating the values and display the either input box or select.Effort So Far
optgroup
namedFieldOps
and made sure all the operators are named the same but just appended withunderscore
. So,less
will becoreless_
in theFieldOps
optgroup. And set appropriateapply_to
. This works perfectly.filters
-->input
,Definition of valueGetter and input functions in the filters.
function valueGatter_fieldComparison( rule ) { return rule.$el.find( ".rule-value-container" ).attr( "data-value" ); }
data_from_select = function ( id ) { $( id ).parent().attr( "data-value", $( id ).find( ":selected" ).val() ); };
data_from_text = function ( id ) { $( id ).parent().attr( "data-value", $( id ).val() ); };