Handlebars multipleselectbox helper

jQuery -- Posted on May 15, 2022

Handlebars multipleselectbox helper

              
                Handlebars.registerHelper("makeSelectBoxMultiple", function(name, value, options){
       let items = options;
       let output = '<label for="'+name+'" class="form-label">'+name+'</label><select class="form-control" name="'+name +'" multiple="multiple">'
       for(let val in items){
         let id = parseInt(items[val].id);
         let selected = false;
         for(let item in value){
             if(parseInt(value[item].id)==id){
               selected = true;
             }
         }
         if(selected==true){
           output +='<option value="'+ id +'" selected>'+items[val].name +'</option>';
         }
         else{
             output +='<option value="'+ id +'">'+items[val].name +'</option>';
         }
       }
       output += '</select>'
       return output;
     });
                  
   
            

Related Posts