[ic] Date widget default
Stefan Hornburg
racke at linuxia.de
Wed Jan 14 07:15:28 EST 2004
On Mon, 11 Nov 2002 08:53:56 -0800
paul jordan <paul at gishnetwork.com> wrote:
> Hi all
>
> Does anyone know a work around for the date widget WRT a blank entry??
>
> It seems it defaults to today's date, well, not only is this not a
> "unknown date" but it will save as today's date when edited (i.e.,
> table-editor)
>
> I added UI_DATE_BEGIN and UI_DATE_END to 1900 and 2010 respectively. It
> is for storage of birthdays and anniversaries. that go back to around
> 1910.
>
> I put the begin date at 1900, so I could use the year 1900 as the flag
> for "year unknown", which is kind of a cheesy hack.
>
> The Problem lies when we have a client, and we don't know their, let's
> say, birth date at all... So, we have a blank entry for that column
> (which is normal), but upon utilizing the date widget, it WILL show a
> date, and this can be confusing, not to mention the above problem with
> table editor. I don't want to kill the widget of no date is found,
> because there may be a point in time we will get the date from them.
>
> I suppose if I could add defaults of 0000 00 and 00 for the three
> selects that make up the date widget, would be sufficient... and have
> them always be available for entering and/or changing a/part date to
> 0000 (as in "unknown")
>
> Sometimes we have the month and day but no year, and sometimes we only
> know the year.
>
> If there is a way to extend this in meta, I do not know the syntax for a
> three in one date select date widget.
>
> I would think the date widget should also handle "no date" and "partial
> no date" as well, or do I misunderstand something? No date and a partial
> date are still useful, at least for us.
>
> I was thinking maybe I can default the column to 00000000 or --------
> then I would like, if there is no date for a person to show [0000] [00]
> [00] or [----] [--] [--] and have the ability for IC to be copasetic
> with just [----] [05] [07] ..... or [1971] [05] [--]
>
> Any Ideas? Where would I handle this? in meta?
>
I needed this for a project, so I came up with the following:
CodeDef date Widget 1
CodeDef date Routine <<EOR
sub {
my ($opt) = @_;
my @Months = qw(January February March April May June July August September October November December);
my $name = $opt->{name};
my $val = $opt->{value};
my $extra;
$extra = " $opt->{extra}" if $opt->{extra};
if($val =~ /\D/) {
$val = $Tag->filter('date_change', $val);
}
# month selector
my $sel = 0;
my $out = qq{<SELECT$extra NAME="$name">};
my $o;
my $num = substr($val, 4, 2);
unless ($num > 0 && $num <= @Months) {
$out .= qq{<OPTION VALUE="" SELECTED>} . errmsg('NA') . '</OPTION>';
$sel = 1;
}
for (my $i = 1; $i <= @Months; $i++) {
my $m = sprintf("%02d", $i);
$o = qq{<OPTION VALUE="$m">} . errmsg($Months[$i-1]) . '</OPTION>';
($out .= $o, next) unless ! $sel and $val;
$o =~ s/>/ SELECTED>/ && $sel++
if $num eq $m;
$out .= $o;
}
$out .= qq{</SELECT><INPUT TYPE=hidden NAME="$name" VALUE="/"><SELECT$extra NAME="$name">};
# day selector
$sel = 0;
$num = substr($val, 6, 2);
unless ($num > 0 && $num <= 31) {
$out .= qq{<OPTION VALUE="" SELECTED>} . errmsg('NA') . '</OPTION>';
$sel = 1;
}
for(1 .. 31) {
$o = sprintf(qq{<OPTION VALUE="%02d">%s</OPTION>}, $_, $_);
($out .= $o, next) unless ! $sel and $val;
$o =~ s/>/ SELECTED>/ && $sel++
if $num eq $_;
$out .= $o;
}
$out .= qq{</SELECT><INPUT TYPE=hidden NAME="$name" VALUE="/"><SELECT$extra NAME="$name">};
# year selector
$sel = 0;
$num = substr($val, 0, 4);
my $by = 1880;
my $ey = 2020;
unless ($num >= $by && $num <= $ey) {
$out .= qq{<OPTION VALUE="" SELECTED>} . errmsg('NA') . '</OPTION>';
$sel = 1;
}
for($by .. $ey) {
$o = qq{<OPTION VALUE="$_">$_</OPTION>};
($out .= $o, next) unless ! $sel and $val;
$o =~ s/>/ SELECTED>/ && $sel++
if $num eq $_;
$out .= $o;
}
$out .= qq{</SELECT>};
return $out;
}
EOR
Ciao
Racke
--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team
More information about the interchange-users
mailing list