Formats a value for javascript code.
public static formatJsVal ( string $value ) : string | ||
$value | string | String to be formatted. |
return | string | formatted value. |
/** * 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; }