Beispiel #1
0
 /**
  * Outputs the initialization script for the validation and replaces the predefined js template stuff for the actual fieldnames and values.
  * @param \Module\HTMLForm\HTMLInputFormElement The element to apply onInit to.
  * @param string The script to apply. This is the sum of all the functions.
  * @param array An array containing all the function calls.
  * @param string The events to bind to.
  */
 public static final function prepareValidationJS(\Module\HTMLForm\HTMLInputFormElement $element, $validationScript, array $functionCalls, $events)
 {
     $validationScript = '
         $(function() {
             $("#{ID}").on("' . $events . '", function() {
                 if ({FUNCTIONS}) {
                     $(this).removeClass("error notice");
                 }
                 else {
                     $(this).addClass("error");
                 }
             });
         });' . $validationScript;
     $validationScript = str_ireplace('{FUNCTIONS}', implode('&&', $functionCalls), $validationScript);
     $validationScript = str_ireplace('{ID}', $element->getId(), $validationScript);
     return $validationScript;
 }