CA Service Management

Expand all | Collapse all

Validation for Date Field in detail_in.htmpl

Jump to Best Answer
  • 1.  Validation for Date Field in detail_in.htmpl

    Posted 06-19-2015 10:25 AM

    I would like to know if there is a way to validate a date field in a call_req detail web form.


    This date must be typed by customers and then SDM must check if it's later than now (or alternatively, later than ticket's last update date).

    I found out that date control doesn't have an evt property, so I guess this validation couldn't be made through a javascript function.



  • 2.  Re: Validation for Date Field in detail_in.htmpl
    Best Answer

    Posted 06-19-2015 11:19 AM

    hi,

    as I think date can be validated by js as well as by spel.

     

    js variant:

    add event to your date field, I prefer to use event listener.

    function attEvt(eventName, target, handlerName){
      if (target.addEventListener) {
      target.addEventListener(eventName, handlerName, false);
      } else if (target.attachEvent) {
      target.attachEvent("on" + eventName, handlerName);
      } else {
      target["on" + eventName] = handlerName;
      }
    }
    
    
    
    

    usage:

    function z_validate(evt){
      if(string_to_date('', evt.target.value, '') < Math.round(Date.now() / 1000)){
      alert("ERROR!");
      evt.target.value = "";
      }
    }
    attEvt("blur", ahdframe.document.getElementsByName('SET.time_stamp')[0], z_validate);
    
    
    
    

     

    spel variant:

    mod file:

    MODIFY cr POST_VALIDATE z_check_date(z_my_date) 1337; // REPLACE z_my_date WITH YOUR DATE ATTR
    
    
    
    

    spl file:

    cr::z_check_date(...)
    {
      date znow, z_my_new_date;
      znow = now();
      z_my_new_date = argv[3];
      if((int)znow > (int)z_my_new_date ){
      logf(ERROR, "Your stdlog error here [%s]", ref_num);
      set_error(1);
      set_return_data(format("Your html error here [%s]", ref_num));
      return;
      }
    }
    
    
    
    


  • 3.  Re: Validation for Date Field in detail_in.htmpl

    Posted 06-22-2015 09:31 AM

    It's work ! Thanks.