Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apex always execute validation

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?

like image 292
michael nesterenko Avatar asked Dec 21 '25 15:12

michael nesterenko


1 Answers

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);
like image 101
Tom Avatar answered Dec 23 '25 23:12

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!