Tuesday 1 December 2015

display check-box dynamicaly


python code
@frappe.whitelist()
def get_test_data(test_group):
    return {
    "get_test_data": frappe.db.sql("""select name from `tabTest Name` where test_group='%s' order by name"""%(test_group),debug=1, as_list=1)
    }  


JavaScript Cod:
we can use $each or for loop to print check box dynamically


frappe.call({
            method: "sample_register.sample_register.page.jobboard.jobboard.get_test_data",
            type: "GET",
            args: {
                "test_group": "Test Group 2"
            },
            callback: function(r){
                if(r.message){
                    me.test_data = r.message;

                    //$each to apend data, here test is html field
                $.each(r.message, function(idx, val){
                     $("<input type='checkbox' name='"+val[0]+"' value='Bike'>"+val[0]+"<br>").appendTo(d.fields_dict.test.wrapper);


                });
                //for loop to apend data
                    for (var i = 0; i<r.message.get_test_data.length; i++) {
                        msgprint(r.message.get_test_data[i][0]);
                        $("<input type='checkbox' name='"+r.message.get_test_data[i][0]+"' value='Bike'>"+r.message.get_test_data[i][0]+"<br>").appendTo(d.fields_dict.test.wrapper);

                }
            }
        }); 


 manual way
 $("<div style='min-height: 200px'><p>Select Test which you want to perform</p>\
        <input type='checkbox' name='vehicle' value='Bike'>Test One<br>\
        <input type='checkbox' name='car' value='Bike'>Test Two<br>\
        <input type='checkbox' name='bike' value='Car'>Test Three<br>\
         ").appendTo(d.fields_dict.test.wrapper);

No comments:

Post a Comment