jstree
jstree copied to clipboard
Update search call back on checkbox change
Version : jstree-3.3.16-0-gb3135cf
I used regexp in search callback and its working if the user input ^ in the field
search_callback : function (str, node) { try { return node.data.fullname.match(new RegExp(str)); } catch(ex) { return false; } },
I have a checkbox for using regex (word start with) so I can add ^ in the begging of the search word
<input type="text" id="search_word" value="" class="input" style="margin:0em auto 1em auto; display:block; padding:4px; border-radius:4px; border:1px solid silver;" />
<label>start with </label>
<input type="checkbox" id="search_start_with" name="search_start_with" value="1" >
If checked the function will add ^ in the begging of the search word I tried several methods but it didn't not work, the last one works if the box is unchecked the checked, but when unchecking it doesn’t work
The code
$(function () {
$('#search_word').keyup(function(){
$('#ajax').jstree(true).show_all();
var value = $(this).val();
if($("#search_start_with").is(':checked')){
value = '^'+value ;
}
$('#search_start_with').change(function() {
if($(this).is(":checked")) {
value = '^'+value ;
$("#ajax").jstree("search",value);
return;
}
});
$("#ajax").jstree("search", value);
});
});
Can this be solved if the box checked then add ^ else use the search word without it?