Reputation: 14439
Is it possible to execute validations on page load regardless if it is submitted or just loaded?
I need to implement it for ordinary validations created in processing page section and for min max validations assigned to number field.
Is it possible to implement?
Upvotes: 3
Views: 3608
Reputation: 7028
Indeed: having a server side validation will throw an error, but the page has submitted and thus the changed values are in session state. You could try to prevent this by having a plsql validation which would blank out the session state value when an error occurs, but might not be optimal. I think that some javascript could alliviate some of the trouble.
Here is some javascript that restricts the selectable ranges in the to and from datepickers. It won't allow a user to pick a larger from than to date, and vice versa. It also sets the item to readonly, so that the user has to select through the datepicker and can not alter it by hand.
Page > Javascript > Function and Global Variable Declaration
function f_check_date(){
var lFrom = $("#P6_DATE_FROM").datepicker("getDate"),
lTo = $("#P6_DATE_TO").datepicker("getDate");
if(lFrom > lTo || lTo < lFrom){
//in case it does happen
$("#P6_DATE_FROM").val('');
$("#P6_DATE_FROM").val('');
alert('Please select a valid date range.');
} else {
//when a date changes, the other datepicker has to be altered so the
//range is adjusted
$("#P6_DATE_FROM").datepicker("option","maxDate",lTo);
$("#P6_DATE_TO").datepicker("option","minDate",lFrom);
};
};
Dynamic Action, Page Load, Execute javascript
//on load, set the datepicker range in case a date is already present
//when the date changes, call the datecheck function
//and set item to readonly
$("#P6_DATE_FROM")
.datepicker("option","maxDate",$("#P6_DATE_TO").datepicker("getDate"))
.change(f_check_date)
.prop("readonly",true);
$("#P6_DATE_TO")
.datepicker("option","minDate",$("#P6_DATE_FROM").datepicker("getDate"))
.change(f_check_date)
.prop("readonly",true);
Upvotes: 1