0

I have a bunch of select elements in a form that I am using the jQuery Chosen plugin. I am not able to reset the form:

I have referred this link but nothing worked for me:

jQuery Chosen reset

My code is:

 $scope.share = function (share_data,type, doc_type) {
        // $('.userlist').chosen().destroy()
            $scope.sharedgroup = [];
            $scope.users_select = "";
            // $scope.sharetype = type;
            $scope.doc_type = doc_type; 
            $scope.shareid = share_data._id;
            console.log(share_data)
            $('#shareModal').modal('toggle');
        $scope.getclientshare(share_data);  
        // $(".userlist").val([]).trigger('chosen:updated')
        $scope.getfilterlist=function(){
         $http.post("/getuserslist", { 'users': 'list'}).then(function (response) {
            $scope.userlist = response.data
            $(".userlist").val('').trigger("chosen:updated");
            $timeout(function () {
               $(".userlist").chosen({ disable_search_threshold: 3 });
                $scope.page_loader = false;            
          });

         });  
        }
        $scope.getfilterlist();


    };

Is there any mistake I have done?

Alessio
  • 3,404
  • 19
  • 35
  • 48
Vishnu
  • 745
  • 12
  • 32
  • What do you expect `destroy` to do? *Delete* the selected elements? In that case I would expect `$('.userlist').chosen().destroy()` to work (I do not know the Chosen plugin, but that is how a jQuery-like fluent syntax ought to operate). – LSerni Aug 20 '18 at 05:44
  • destroy will remove the selected one. $('.userlist').chosen().destroy() am getting is not a function . https://harvesthq.github.io/chosen/ – Vishnu Aug 20 '18 at 05:46

3 Answers3

3

$(".chosen-select").val('').trigger("chosen:updated");

Please try this, it will set a default value in your dropdown.

shubham chhapre
  • 296
  • 1
  • 14
0
 $(".userlist").html('').chosen();
hamed hossani
  • 986
  • 2
  • 14
  • 33
0

see code below

 $(".chzn-select").chosen();
$('a').click(function(){
    $(".chzn-select").val('').trigger("liszt:updated");
});​
neel upadhyay
  • 344
  • 2
  • 10
  • While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Jun 28 '21 at 05:57