I have an int field in one of my database tables with a default value of 10485760 defined. When I attempt to add a new row to the table, the input template that appears does not display the default value! So, if I want the default value to be assigned to the row I am adding, I have to type it in manually which doesn't seem to make sense.
Think I may have found/fixed the problem in the view_table.cgi code.
In the "Show rows, some of which may be editable" portion of the script, I edited the following code (under "Show multi-line row editor" section) to now read as follows:
elsif ($str[$j]->{'type'} =~ /\((\d+)\)/) {
# Show as known-size text
local $nw = $1 > 70 ? 70 : $1;
# When adding new row - use default valu
es where present
if ($in{'new'} &&
$str[$j]->{'default'} ne '') {
$et .= &ui_textbox($nm, $str[$j]
->{'default'} , $nw);
}
else {
$et .= &ui_textbox($nm, $d[$j],
$nw);
}
}
Similarly, I edited the corresponding portion under the "Show one-line row editor" section:
elsif ($str[$j]->{'type'} =~ /\((\d+)\)/) {
# Show as known-size text
local $nw = $1 > 70 ? 70 : $1;
# When adding new row - use default valu
es where present
if ($in{'new'} &&
$str[$j]->{'default'} ne '') {
push(@cols,
&ui_textbox($nm, $str[$j]->
{'default'}, $nw));
}
else {
push(@cols,
&ui_textbox($nm, $d[$j], $n
w));
}
}
I only changed the "known text-size" portions as that is the only bit that was causing issues for me. But I guess the same fix could also be applied to the other areas.
Cheers,
Dan
Actually, just leaving the field blank should cause the default to be used. The default is used by MySQL when a row is added and no value is given for that field..
Mmmmmm...didn't seem to be assigning any default value at all when I clicked "Save". For fields that allowed a null value it would just make them null and for fields that disallowed null it would throw up an error. But if it works when you try it then I guess there could be an issue with the way my table is configured? Will have to have a play with it. Thanks anyway.
Ok, it looks like you are right .. defaults are not being handled as expected. To fix this I will have them appear in the appropriate fields when a new row is being added, as you suggested initially.