In the report development process, we often need to check the query interface date. For example, there are two parameters: start date and end date, we want to verify that: the start date and end date cannot be empty, the end date must be after the start date and the end date must be within a certain time period after the start date, otherwise the relevant information can be added to the query button. Below we introduce the specific settings by Finereport.
Specific as follows:
650) this.width=650; "Src=" http://img.blog.csdn.net/20160511151924759?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/center "/>
It can be seen that the following error is reported.
The design of the template is not focused on this side, set the following template interface:
650) this.width=650; "Src=" http://img.blog.csdn.net/20160511152018041?watermark/2/text/ Ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/center "/>
To add click events to the Query button, the specific JS code is as follows:
Var start =this.options.form.getwidgetbyname ("StartTime"). GetValue (); var end = This.options.form.getWidgetByName ("Endtime"). GetValue (); if ( start == "" | | start==null) { //Determines whether the start date is empty alert ("error, start time cannot be empty"), prompt when the //start date argument is empty return false; }; if (end == "" | | End==null) { //Determines whether the end date is empty alert ("error, end time cannot be empty"), //End date argument is empty return false; }; if ( start > end) { // Determine if the start date is greater than the end date alert ("Error, start time cannot be greater than end time"), //start date is greater than End date prompt Return false; }var startdate = newdate (start); //Convert start date to date Var enddate = newdate (end); //converts the end date into a date type var subdate = ( enddate-startdate)/ (1000 *60 *60 *24); //subtract two datesThe number of milliseconds converted to days if (subdate>15) { //Determines whether the end date exceeds 15 days after the start date alert ("Error, end date must be within 15 days of the start date"); //the end date exceeds the start date 15 days after the prompt Return false;}
Although the parameter control can also set the check, but the parameter control to click on the control before it can be verified, so the parameter interface can not be empty and the comparison check needs to be set in the Query button, so instead of all put in the query button to verify.
after you set up the view template, select the start time and end time so that the two dates will differ by more than a few days, the above dialog box pops up.
because FineReport 's report interface was shown in the previous section, and I've tried it all over the browser. Just the above JS code in Firefox, Google IE9 and other browsers do not have a problem, but in IE8 and IE8 The following version of IE Browser, A warning box that determines the difference between two dates does not work. You can swap the following code:
Var start =this.options.form.getwidgetbyname ("StartTime"). GetValue (); var end =this.options.form.getwidgetbyname ("Endtime"). GetValue (); if ( start == "" | | start==null) { //Determines whether the start date is empty alert ("error, start time cannot be empty"); // Prompt return false; }; if When the start date argument is empty (end == "" | | End==null) { //Determines whether the end date is empty alert ("error, end time cannot be empty"); // Prompt return false; }; if When the end date parameter is empty ( start > end) { //Determines whether the start date is greater than the end date alert ("Error, Start time cannot be greater than end time "), //start date is greater than End date prompt return false; } var adate = start.split ("-") var startdate &Nbsp;= new date (adate[1] + '-' + adate[2] + '-' + adate[0]) //converted to MM-DD-YYYY format alert ( StartDate); Var adate = end.split ("-") var enddate = new date (adate[1] + '-' + aDate[2] + '-' + adate[0]) alert (enddate);var subdate= (enddate - startdate) /1000/ 60/60/24) //converts the difference in milliseconds to days alert ( Subdate); if (subdate>15) { //Determines whether the end date exceeds 15 days after the start date alert ("Error, end date must be within 15 days from the start date" ); //the end date is 15 days after the start date, prompt return false; }
Web Reporting Tools JS Development Date Check