jQuery

jQuery

Explore jquery code snippets and tutorials

jQuery

Jquery function for django display error data

<p>This code is a JavaScript function named <code>display_error_data(data)</code>. It seems to handle error data received as input and displays the errors in the console and on the web page as …

javascript
1
2
3
4
5
6
7
8
function display_error_data(data){
      console.info("error:",data);
      $.each(data['errors'], function( index, value ) {
        console.info(index, ':', value);
        $("[name='" +index + "']").addClass('is-invalid');
        $("[name='" +index + "']").after("<div class='invalid-feedback'>"+ value + "</div>");
      });
    }
jQuery

Handlebars checkbox helper

Handlebars checkbox helper

javascript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Handlebars.registerHelper("makeCheckBox", function(name, label, value){
        let output = '<div class="form-check">';
        output += '<input class="form-check-input" name="'+ name + '"' +'type="checkbox" value="' + value + '"'
        console.info(typeof(value), value);
        if(value === true){
             output += 'checked ';
        }
        output +='id="' + name + 'Default"' + '>';
        output +='<label class="form-check-label" for="' + name + 'Default">' +
                    label + '</label></div>';
        return output;
    });
jQuery

Handlebars multipleselectbox helper

Handlebars multipleselectbox helper

javascript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
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;
     });
jQuery

Handlebars selectbox helper

Handlebars selectbox helper

javascript
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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;
     });