Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]adding JS date validation to html composer

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED]adding JS date validation to html composer
 Login/Join
 
Member
posted
Good Morning All,
I just migrated to App Studio and am trying to add a JavaScript function to check some date validation that is not rolled into the product as a option that I can find. What I have is a HTML page with 3 parameters. 2 calendar boxes and a list of location, everything works great as long as the users use the calendar popup to choose there dates, however if they choose to enter the dates manually and put a end date that is before the start date all of the reports on all of the tabs in the portal error out, which is expected, so what I want to do is add a js function to validate and show an alert instead of rendering all the reports ( there are several per page) and putting an error message in each panel...... should be straight forward. I found a scrip that does exactly what I want added it to the Javascript tab in app studio added the Task but nothing happens. Any assistance would be appreciated. Here is the JS code.
if(typeof(bRuntime) != 'undefined') {
// TODO: Add your inline runtime code here
}
//Begin function window_onload
function window_onload() {
UpdateData();
// TODO: Add your event handler code here
//add onInitialUpdate() function to make changes before initial run of the reports
}
//End function window_onload


//--------------------------------------------------------------------------
//This function verifies if the start date is prior to end date.
//--------------------------------------------------------------------------


//Begin function checkEnteredDates
function checkEnteredDates(STARTDATE,ENDDATE){
//seperate the year,month and day for the first date
var stryear1 = STARTDATE.substring(6);
var strmth1 = STARTDATE.substring(0,2);
var strday1 = STARTDATE.substring(5,3);
var date1 = new Date(stryear1 ,strmth1 ,strday1);
//seperate the year,month and day for the second date
var stryear2 = ENDDATE.substring(6);
var strmth2 = ENDDATE.substring(0,2);
var strday2 = ENDDATE.substring(5,3);
var date2 = new Date(stryear2 ,strmth2 ,strday2 );
var datediffval = (date2 - date1 )/864e5;
if(datediffval <= 0){
alert("Start date must be prior to end date");
return false;
}
return true;
}
//End function checkEnteredDates

and Thanks to Tom Flynn for putting this js function out where we can find it.

This message has been edited. Last edited by: <Emily McAllister>,


WebFOCUS 8.05
Windows , Excel, PDf, HTML
 
Posts: 27 | Location: Nashville Tn | Registered: January 12, 2010Report This Post
Master
posted Hide Post
It looks like your code might not be picking apart the date correctly, particularly the day. But I haven't tested it.

Here is a date range validation for two calendar controls, "calendar1" (Start date) and "calendar2" (End date). In the calendar Settings panel, I chose the MDYY date format (MM/DD/YYYY) and checked the "Send unformatted value" box so the date ends up MMDDYYYY with no slashes. The dates are then converted to YYYYMMDD for comparison:

function form1Submit_onclick(event) {
    var bmdyy = IbComposer_getCurrentSelection("calendar1");
    var emdyy = IbComposer_getCurrentSelection("calendar2");
 
    var byymd = bmdyy.toString().substr(4,4) + bmdyy.toString().substr(0,4);
    var eyymd = emdyy.toString().substr(4,4) + emdyy.toString().substr(0,4);

    if (eyymd < byymd) {
        alert("Start date cannot be greater than end date");
        event.stopImmediatePropagation();
        return;
    }
}

If you have this code inside a submit button event, like this example, the "event.stopImmediatePropagation()" function will abort the call to the FEX file after alerting the user about the date range error.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Report This Post
Member
posted Hide Post
Thank you Squatch,
Tried your code, however since I am doing sql passthru for all of the reports and graphs when i select the "Send unformulated value" option I start getting sql errors about the date time conversion. is there a way to do this function without sending the dates as unformatted value?


WebFOCUS 8.05
Windows , Excel, PDf, HTML
 
Posts: 27 | Location: Nashville Tn | Registered: January 12, 2010Report This Post
Master
posted Hide Post
Sure, try substituting in these lines if you are using MM/DD/YYYY format:

    var byymd = bmdyy.toString().substr(6,4) + bmdyy.toString().substr(0,2) + bmdyy.toString().substr(3,2);
    var eyymd = emdyy.toString().substr(6,4) + emdyy.toString().substr(0,2) + emdyy.toString().substr(3,2);


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Report This Post
Master
posted Hide Post
quote:
...however if they choose to enter the dates manually and put a end date that is before the start date all of the reports on all of the tabs in the portal error out...

There is a read-only property for the calendar control that can prevent users from manually typing in a date, if you are interested in using that.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
 
Posts: 594 | Location: Michigan | Registered: September 04, 2015Report This Post
Member
posted Hide Post
Squatch,
Thank you so much,
Works like a charm, I would be interested in the read-only property, but im trying to teach myself javascript at the same time, so this was fantastic,
thank you again for the assistance.


WebFOCUS 8.05
Windows , Excel, PDf, HTML
 
Posts: 27 | Location: Nashville Tn | Registered: January 12, 2010Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED]adding JS date validation to html composer

Copyright © 1996-2020 Information Builders