public function clientJQuery($fieldType, Staple_Form_Element $field) { switch ($fieldType) { case 'Staple_Form_SelectElement': $fieldid = "#{$field->getId()}"; $valstring = "#{$field->getId()} option:selected"; break; case 'Staple_Form_RadioGroup': $fieldid = "input:radio[name={$field->getName()}]"; $valstring = "input:radio[name={$field->getName()}]:checked"; break; case 'Staple_Form_CheckboxElement': return ''; break; default: $fieldid = "#{$field->getId()}"; $valstring = $fieldid; } $script = "\t//Phone Validator for " . addslashes($field->getLabel()) . "\n"; $script .= "\tif(!(" . self::REGEX . ".test(\$('{$valstring}').val())))\n\t{\n"; $script .= "\t\terrors.push('" . addslashes($field->getLabel()) . ": \\n{$this->clientJSError()}\\n');\n"; $script .= "\t\t\$('{$fieldid}').addClass('form_error');\n"; $script .= "\t}\n"; $script .= "\telse {\n"; $script .= "\t\t\$('{$fieldid}').removeClass('form_error');\n"; $script .= "\t}\n"; return $script; }
/** * @see Staple_Form_Validator::clientJQuery() */ public function clientJQuery($fieldType, Staple_Form_Element $field) { switch ($fieldType) { case 'Staple_Form_SelectElement': $fieldid = "#{$field->getId()}"; $valstring = "#{$field->getId()} option:selected"; break; case 'Staple_Form_RadioGroup': $fieldid = "input:radio[name={$field->getName()}]"; $valstring = "input:radio[name={$field->getName()}]:checked"; break; case 'Staple_Form_CheckboxElement': return ''; break; default: $fieldid = "#{$field->getId()}"; $valstring = $fieldid; } $script = "\t//Selection Validator for " . addslashes($field->getLabel()) . "\n"; $script .= "\tif(-1 == \$.inArray(\$('{$valstring}').val(),["; foreach ($this->arrayvalues as $value) { $script .= "'{$value}',"; } $script = substr($script, 0, strlen($script) - 1); $script .= "]))\n\t{\n"; $script .= "\t\terrors.push('" . addslashes($field->getLabel()) . ": \\n{$this->clientJSError()}\\n');\n"; $script .= "\t\t\$('{$fieldid}').addClass('form_error');\n"; $script .= "\t}\n"; $script .= "\telse {\n"; $script .= "\t\t\$('{$fieldid}').removeClass('form_error');\n"; $script .= "\t}\n"; return $script; }