0
  1. I have a label with id lblResult

  2. I have the following code:

    @(Html.TreeView(Model) .EmptyContent("root") .Children(m => m.Childs) .HtmlAttributes(new { id = "tree" }) .ChildrenHtmlAttributes(new { @class = "subItem" }) .ItemText(m => m.AssetNumber) .ItemTemplate( @ @*@item.AssetNumber*@ ) )
  3. Then, I have the following code on the view:

@using (Html.BeginForm("AssetTypeIndex", "ControlFiles", FormMethod.Get))
{
<div class="row">
<div class="col-lg-offset-2 col-lg-8 col-lg-offset-2">
<div class="form-inline">
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Search</span>
@Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { @class = "form-control" })
<span class="input-group-btn">
<button class="btn btn-default" type="submit" value="Search">View</button>
</span>
</div>
<div class="pull-right">
<a [email protected]("AssetTypeCreate", "ControlFiles") class="btn btn-default">Create New</a>
</div>
</div>
</div>
</div>
}

  1. On script section:

    $(function () { var selectedData; $('#jstree').jstree({ "core": { "multiple": true, "check_callback": true, 'themes': { "responsive": true, 'variant': 'small', 'stripes': false, 'dots': true } }, "types": { "default": { "icon": "glyphicon glyphicon-record" }, "root": { "icon": "glyphicon glyphicon-ok" } }, "plugins": ["dnd", "state", "types", "sort"] }).on('changed.jstree', function (e, data) { var i, j, r = []; for (i = 0, j = data.selected.length; i

If you see on the code above. There's a submit button which is trigger the search function on the controller.
My question is, Is it possible to run the 'Search Function' without clicking the button? I want to run the 'Search Function' when lblResult received the text from jsTree, it means when lblResult text is change.

Please advice.
Thank you.

4
  • I want ask you when text in lblResult was be changed? Commented Mar 1, 2018 at 8:08
  • @BaiNguyen, it changes when I clicking a node on my jsTree. Cheers, Commented Mar 1, 2018 at 8:25
  • So i think when you click this, you had better submit search form. Commented Mar 1, 2018 at 8:29
  • @BaiNguyen, I didn't get you. I am new on MVC. Could you give an answer section please? Also, when I clicking on the node. I want to display the value also on Label. That's why I've the question above. Commented Mar 1, 2018 at 8:36

2 Answers 2

0
Option 1: When clicking a node on your jsTree trigger that submit function by simulating a mouse-click using click method. As you know for sure the label will be changing.

@using (Html.BeginForm("AssetTypeIndex", "ControlFiles", FormMethod.Get)){
    <div class="row">
        <div class="col-lg-offset-2 col-lg-8 col-lg-offset-2" style="margin-top:-5px;">
            <div class="form-inline">
                <div class="input-group">
                    <span class="input-group-addon" id="basic-addon1">Search</span>
                    @Html.TextBox("SearchString", ViewBag.CurrentFilter as string, new { @class = "form-control" })
                    <span class="input-group-btn">
                        <button class="btn btn-default" id="submitSearch" type="submit" value="Search">View</button>
                    </span>
                </div>

                <div class="pull-right">
                    <a [email protected]("AssetTypeCreate", "ControlFiles") class="btn btn-default">Create New</a>
                </div>
            </div>
        </div>
    </div>
}
$("#submitSearch").click(); // use the code when clicking a node on jsTree

Option 2: If you are manually changing the label by entering in a textbox then use the keyup event to trigger submit function.

$(function(){
  $("#lblreasult").on('keyup', function(){
    $("#submitSearch").click();
  });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Sorry for my late reply, when you click on a node in your jsTree ex: a tag have id is node1, you can remove this code

<span class="input-group-btn">
     <button class="btn btn-default" id="submitSearch" type="submit" value="Search">View</button>
 </span>

or add this css code

#submitSearch{display:hidden}

I edited a bit in your code

$('#jstree').on('changed', function (e, data) { 
    var i, j = data.selected.length, r = []; 
    for(i = 0,  i < j; i++) { 
        r.push(data.instance.get_node(data.selected[i]).text); 
    } 
    $('#event_result').html('Selected: ' + r.join(', ')); 
    $('#lblResult').text('your text here');//
    $('form').submit();
});

1 Comment

I use this when clicking node --> <a href="@item.AssetID" desc="@item.AssetID">@item.AssetNumber</a> ... Then on the script sect... $('#jstree') // listen for event .on('changed.jstree', function (e, data) { var i, j, r = []; for(i = 0, j = data.selected.length; i < j; i++) { r.push(data.instance.get_node(data.selected[i]).text); } $('#event_result').html('Selected: ' + r.join(', ')); }) // create the instance .jstree();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.