Custom Script Validation on Screens… Again!

HR.Net is a mysterious beast! Something may work in one place, but same copy-pasted might not work in the other place. Last couple hours I have spent fighting Screen Validation again. I have already written about this feature a few times and this time none of these methods worked for me, even though I have not done anything different. No idea what happened with HR.Net and why old versions work in old screens, but not in new screens. Because HR.Net is full of shitty bugs, sometimes javascript function Page_ClientValidate is not available on a screen – I noticed that it disappears as soon as you add a grid to a screen. And in all my previous validations I was relying on this function to be present and called by the framework (“Page_ClientValidate” function which is provided by underlying .Net framework).

So after a lot of detective work I have found that save button triggers event HRnet.Form.UI.Buttons.Save.action and I could override this function. But “Save And Close” button was triggering different event HRnet.Form.UI.Buttons.SaveAndClose.action, so both of these should be overriden if both buttons are available.

Here is the basic script that ensures that some fields are filled in on the screen:

// override click on Save button
(function() {
  var proxied = HRnet.Form.UI.Buttons.Save.action;
  HRnet.Form.UI.Buttons.Save.action = function() {
    
    if(MyValidate() === false){
        return false;
    }
    
    return proxied.apply( this, arguments );
  };
})();

// override click on Save And Close button
(function() {
  var proxied = HRnet.Form.UI.Buttons.SaveAndClose.action;
  HRnet.Form.UI.Buttons.SaveAndClose.action = function() {
    
    if(MyValidate() === false){
        return false;
    }
    
    return proxied.apply( this, arguments );
  };
})();



function MyValidate(){
    var field1 = $HRnet("Field1").getDisplayValue();
    var field2 = $HRnet("Field2").getDisplayValue();
    var field2 = $HRnet("Field3").getDisplayValue();

    var ErrMsg ="";
    var validate = true;

    if (isBlank(field1)){
        ErrMsg += "You need to fill in 'Field 1'\n";
        validate = false;
    }

    if (isBlank(field2)){
        ErrMsg += "You need to fill in 'Field 2'\n";
        validate = false;
    }
   
    if (isBlank(field3)){
        ErrMsg += "You need to fill in 'Field 3'\n";
        validate = false;
    }
            
    if (!validate){
        alert(ErrMsg);
        return validate;
    }
}


function isBlank(val){
    if(val==null){
        return true;
    }
    for(var i=0;i
											
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to Custom Script Validation on Screens… Again!

  1. Tony says:

    What a wonderful website, I had a query which I wonder if you might know the answer to… is it possible to align the text within the label fields on forms? I had managed to use and this worked! It did! For about 30 seconds, because when I closed the form to show someone and opened it back up, it was no longer aligned right and I could never replicate it! Thanks!

    • admin says:

      Hm.. I always align labels in forms manually and it always takes forever. And not really have thought of doing it via a JS. So I’m guessing this is doable, but I have never done/needed this and I don’t have a snippet of code.

Leave a Reply to Tony Cancel reply

Your email address will not be published. Required fields are marked *