input type='color' fields saving as an array in database but not populating input type ='color' 'value attribute'
I am trying this but not working.
label(for='firstColor') Color 1
input#firstColor(type='color' name='colors' value = colors)
label(for='secondColor') Color 2
input#secondColor(type='color' name='colors' value = colors)
label(for='thirdColor') Color 3
input#thirdColor(type='color' name='colors' value = colors)
I am receiving this data from database:
{colors: Array(3)
0: "#f50000"
1: "#000000"
2: "#000000"
}
And using this code to populate:
$.each(results, function (i,v){
form.find('[name="'+i+'"]').val(v);
})
but no success in populating input color value.
PS: multiple checkboxes, multiple select options working fine using same setup above.
Finally solved it by updating code:
var form = $('#registerForm');
$.each(results, function (i,v){
if(i == 'colors'){
$.each(results.colors, function (a,b){
$('[name="colors['+a+']"]').val(b);
})
}else{
form.find('[name="'+i+'"]').val(v);
}
})
I still want to know how it was working without updating code on multiple checkbox and multiple select but not on multiple color inputs?
If its for a HTML Page, storing the #RRGGBB tag as a string is probably enough.
If its for .NET , it supports building a color from its ARGB Value
System.Drawing.Color c = System.Drawing.Color.FromArgb(int);
int x = c.ToArgb();
so you could just store that int.