Handlebars selectbox helper

jQuery -- Posted on May 15, 2022

Handlebars selectbox helper

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

Related Posts