Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Passing Parameter to JS
dpsiingh
I have two date fields in
TAG_info
(
fromDate => [ html => get_calender("fromDate"),
is_required => 'false',
label => "<strong>Write by date: (dd/mm/yyyy)<strong>",
valid_input => '/^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]/',
error_msg => 'Date format is DD/MM/YYYY',],
toDate => [ html => get_calender("toDate"),
is_required => 'false',
label => "<strong>Review by date: (dd/mm/yyyy)</strong>",
valid_input => '/^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]/',
error_msg => 'Date format is DD/MM/YYYY',],
);
and a function to check for dates
my $varJavaScript = '<script>
function checkDate(fromDate, toDate)
{
if (fromDate > toDate)
{
alert("From Date cannot be greater than To Date");
}
else
{
alert("The Strings are not valid");
}
}
</script>';
1. I am not able to understand how to pass the dates to checkDate method from Tag_Info.
2. Is there any other better way to compare dates.
Find more posts tagged with
Comments
Adam Stoller
You might consider writing
checkDate()
as a perl subroutine and call it from either/both fromDate and/or toDate via the valid_input directive.
You'd need to have the subroutine verify that it has two dates first before actually trying to compare them. Something like (though unverified if this exact code works):
use Date::Manip;
# A sledge hammer - but it will do the job
TAG_info(
fromDate => [
html => get_calender("fromDate"),
label => "...",
valid_input => checkDate($_, __VALUE__(toDate), 0),
error_msg => checkDate($_, __VALUE__(toDate), 1),
],
toDate => [
html => get_calender("toDate"),
label => "...",
valid_input => checkDate(__VALUE__(fromDate), $_, 0),
error_msg => checkDate(__VALUE__(fromDate), $_, 1),
],
);
sub checkDate{
my($fromDate, $toDate, $errmsg) =
@_
;
my($fd, $td) = ('','');
# handle each date separately
if (defined($fromDate) && $fromDate ne ''){
$fd = ParseDate($fromDate);
if (!$fd){
return 0 if (!$errmsg);
return "'$fromDate' is not valid - please enter value in MM/DD/YYYY format";
}
}
if (defined($toDate) && $toDate ne ''){
$td = ParseDate($toDate);
if (!$fd){
return 0 if (!$errmsg);
return "'$toDate' is not valid - please enter value in MM/DD/YYYY format";
}
}
# we have two dates - now compare them
if ($td ne '' && $fd ne ''){
my $flag = Date_Cmp($fd, $td);
if ($flag < 0) {
# fd is earlier than td
return 1;
}
elsif ($flag == 0) {
# fd is the same as td
return 0 if (!$errmsg);
return "Write by and Review by dates cannot be the same";
}
else{
# fd is later than td
return 0 if (!$errmsg);
return "Write by date cannot be after Review by date";
}
}
# if we somehow made it this far, assume success?
return 1;
}
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
sanjeevappa
Hi Fish,
When i test this code it is running fine, but it is accepting anything you enter in date fields it is not at all validating both fields, i think when i call checkDate function in TAG_info under valid_input it is not at all entering the subroutine( sub checkDate { .. }).
Iam not getting why it is not entering the subroutine.
Help will be thank ful.
dp
Adam Stoller
Well - I said it was unverified as to working. All I can suggest at this point is to add debugging...
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
sanjeevappa
Hi ,
While debugging above code i found that on instantiator form the things like "ne" and "eq" won 't work, instead of that you should use != for ne and == for eq.
If any one wants, same thing in future: The working code is:
uWriteByDate => [ html => get_calender("uWriteByDate"),
is_required => 'true',
label => "<strong>Write by date: (dd/mm/yyyy)<strong>",
valid_input => '/^[0-3][0-9]\/[0-1][0-9]\/[0-2][0-9][0-9][0-9]/',
error_msg => 'Date format is DD/MM/YYYY',
],
uReviewByDate => [ html => get_calender("uReviewByDate"),
label => "<strong>Review by date: (dd/mm/yyyy)<strong>",
valid_input => 'validator($_,0)',
error_msg => q{'validator($_,1)'},
is_required => 'true',
],
);
my $uWriteByDate = __VALUE__('uWriteByDate');
if ($uWriteByDate != ' ' && $uReviewByDate != ' ')
{
sub validator {
my($uReviewByDate,$error) =
@_
;
my $flag = Date_Cmp($uWriteByDate, $uReviewByDate);
if ($flag > 0)
{
return(1);
}
else
{ if ($error) {
if ($flag < 0)
{
return("Write date is greater than review date");
} else {
return("Both dates are equal");
}
}
return(0);
}
}
}
nugget_shark
Is the get_calendar a home grown function or TS?
iw_store
Hi,
No u have to develop that function for that u take help of usertask.pm and ipl provided by TS for calender.
By above information u will do that.