formatJsVal() public static method

Formats a value for javascript code.
public static formatJsVal ( string $value ) : string
$value string String to be formatted.
return string formatted value.
Example #1
0
 /**
  * Formats javascript assignment for form validation api
  * with proper escaping of a value.
  *
  * @param string  $key   Name of value to set
  * @param string  $value Value to set
  * @param boolean $addOn Check if $.validator.format is required or not
  * @param boolean $comma Check if comma is required
  *
  * @return string Javascript code.
  */
 public static function getJsValueForFormValidation($key, $value, $addOn, $comma)
 {
     $result = $key . ': ';
     if ($addOn) {
         $result .= '$.validator.format(';
     }
     $result .= Sanitize::formatJsVal($value);
     if ($addOn) {
         $result .= ')';
     }
     if ($comma) {
         $result .= ', ';
     }
     return $result;
 }