In this code, I'm getting the json from backend. Once I find the json availability, I loop and make 5 columns. Once the columns are made, I append after the legend of my form.
Can this be improved any further?
if(data.hasOwnProperty("allLocales")){
var col0 = $("<fieldset />"),
col1 = $("<fieldset />"),
col2 = $("<fieldset />"),
col3 = $("<fieldset />"),
col4 = $("<fieldset />");
$.map(data["allLocales"], function(value, i){
var name = value.name;
if(i % 5 === 0 ){
col0.append($("<label />").text(name).prepend($("<input type='checkbox' />").attr("value", name)));
}else if(i % 5 === 1){
col1.append($("<label />").text(name).prepend($("<input type='checkbox' />").attr("value", name)));
}else if(i % 5 === 2){
col2.append($("<label />").text(name).prepend($("<input type='checkbox' />").attr("value", name)));
}else if(i % 5 === 3){
col3.append($("<label />").text(name).prepend($("<input type='checkbox' />").attr("value", name)));
}else if(i % 5 === 4){
col4.append($("<label />").text(name).prepend($("<input type='checkbox' />").attr("value", name)));
}
})
$("form legend").after(col0,col1,col2,col3,col4).end().find("span.submit").css({display:"block"});
}