Commit ad27622a authored by Chenu Denis's avatar Chenu Denis

Fix matcher

parent ad1fba79
......@@ -22,9 +22,6 @@ $(function() {
},
templateResult:function (data) {
return data.text
},
matcher:function(params, data) {
return groupMatcher (params, data);
}
});
$("[data-selectQuestionBy='multiple']").on("change", function (e) {
......@@ -41,54 +38,3 @@ $(document).on("select2:unselecting","[data-selectQuestionBy='multiple'][data-fo
return false;
}
});
function groupMatcher (params, data) {
data.parentText = data.parentText || "";
// Always return the object if there is nothing to compare
if ($.trim(params.term) === '') {
return data;
}
// Do a recursive check for options with children
if (data.children && data.children.length > 0) {
// Clone the data object if there are children
// This is required as we modify the object to remove any non-matches
var match = $.extend(true, {}, data);
// Check each child of the option
for (var c = data.children.length - 1; c >= 0; c--) {
var child = data.children[c];
child.parentText += data.parentText + " " + data.text;
var matches = groupMatcher(params, child);
// If there wasn't a match, remove the object in the array
if (matches == null) {
match.children.splice(c, 1);
}
}
// If any children matched, return the new object
if (match.children.length > 0) {
return match;
}
// If there were no matching children, check just the plain object
return modelMatcher(params, match);
}
// If the typed-in term matches the text of this term, or the text from any
// parent term, then it's a match.
var original = (data.parentText + ' ' + data.text).toUpperCase();
var term = params.term.toUpperCase();
// Check if the text contains the term
if (original.indexOf(term) > -1) {
return data;
}
// If it doesn't contain the term, don't return anything
return null;
}
......@@ -78,7 +78,7 @@ class selectQuestionBy extends \ls\pluginmanager\PluginBase
'help'=>gT('Choose if user can select multiple or only one choice'),
'caption'=>gT('Dropdown type'),
),
'selectQuestionByForceOne'=>array(
'selectQuestionByForceOne'=>array(// Maybe add an automatic system for mandatory ?
'types'=>'T',
'category'=>gT('Drop down'),
'sortorder'=>140,
......@@ -87,6 +87,15 @@ class selectQuestionBy extends \ls\pluginmanager\PluginBase
'help'=>gT(''),
'caption'=>gT('Disable removing last one'),
),
'selectQuestionByExclusive'=>array(
'types'=>'T',
'category'=>gT('Drop down'),
'sortorder'=>150,
'inputtype'=>'text',
'default'=>'',
'help'=>gT('Work in progress : list of code for exclusive option (disable other, is disable if other are checked)'),
'caption'=>gT('[WIP] Exclusive option'),
),
);
if(method_exists($this->getEvent(),'append')) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment