Focal Point
[SOLVED] Date validation and stop processing

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5027072386

August 01, 2016, 04:51 PM
Joel Elscott
[SOLVED] Date validation and stop processing
I’m using App Studio – HTML Composer with GUI. Within my page I have two calendar controls and a submit button. My goal is to perform a date validation and then stop processing in the event of a validation error. Using JavaScript I was able to do the date validation and throw an alert, but the form is still processing. Is there a way to prevent the submission of the form? I tried using ‘return false’ but that didn’t work. I have a few workarounds I can do, such as using JavaScript to submit the reports instead of the GUI, or I could hide the reports on a date validation error, but hopefully there is an easier way. Thanks!

This message has been edited. Last edited by: Joel Elscott,


WebFOCUS 8.2.03
z/OS
August 02, 2016, 07:56 AM
Squatch
function form1Submit_onclick(event) {
var eventObject = event ? event : window.event;
var ctrl = eventObject.target ? eventObject.target : eventObject.srcElement;

    if (dates_are_okay) {
       ...
    } else {
        // Dates are bad
        event.stopImmediatePropagation();
        return;
    }

}



App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
August 03, 2016, 03:00 AM
subbu_088
Yes it can be done.
Write a function named eg. onValidate()

function onValidate()
{
if(your validation is true)
{
return(0); //it will redirect to run the procedure
}
else
{
return(2); //it will stops the report execution
}
}

This function should be called in the Tasks & Animations by creating a new Requests/Actions => "Javascript Call", Target Type => JavaScript Function, Function Name => onValidate

Followed by this request your procedure should be added next in Requests/Actions.

Thanks
Subbu


WebFOCUS 8.6
Windows, All Outputs
August 03, 2016, 03:26 PM
Joel Elscott
@subbu_088 - this worked perfectly! Thank you! This is the first time I've seen "return(2)" being used, but that's exactly what I needed.

@Squatch - Thank you for the suggestion, but unfortunately I couldn't get event.stopImmediatePropagation to work correctly. It stopped the JavaScript from processing, but then I couldn't get it restarted again when I fixed the date and resubmitted the form. Using Firebug I see that stopImmediatePropagation was an unknown function.


WebFOCUS 8.2.03
z/OS
August 03, 2016, 03:43 PM
Squatch
quote:

@Squatch - Thank you for the suggestion, but unfortunately I couldn't get event.stopImmediatePropagation to work correctly. It stopped the JavaScript from processing, but then I couldn't get it restarted again when I fixed the date and resubmitted the form. Using Firebug I see that stopImmediatePropagation was an unknown function.

It will be unknown if you don't have "event" declared in your function:

function form1Submit_onclick(event) {

Actually, it doesn't have to be "event"... it could be "e" or whatever else you want to call it. You just need to declare something so JavaScript can fill it with data and functions related to whatever the user clicked on.

So if you declare it as "e" in your function, you would call it like this:

e.stopImmediatePropagation();

You already have another solution, so I'm posting this in case anyone else wants to try it. It works fine for me.


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs
August 08, 2016, 11:52 AM
Joel Elscott
@Squatch - Thanks again, the solution you mentioned did fix the unknown function error I was receiving. However it still won't let resubmit the form/submit button after I correct the date. It's like it stops everything on the page I can't do anything after I punch in a bad date. I do have another solution though, so I will definitely keep this in mind for in the future.


WebFOCUS 8.2.03
z/OS
August 08, 2016, 12:58 PM
Squatch
quote:
Originally posted by Joel Elscott:
However it still won't let resubmit the form/submit button after I correct the date.

Try stopPropagation() instead of stopImmediatePropagation().


App Studio
WebFOCUS 8.1.05M
Windows, All Outputs