required = $Required;
parent::__construct();
}
public function useLabels($flag) {
$this->useLabels = $flag;
}
/**
* Clears all the validation from this object.
*/
public function removeValidation(){
$this->required = null;
}
/**
* Debug helper
*/
function debug() {
if(!is_array($this->required)) return false;
$result = "
";
foreach( $this->required as $name ){
$result .= "- $name
";
}
$result .= "
";
return $result;
}
function javascript() {
$js = "";
$fields = $this->form->Fields();
foreach($this->form->Fields()->dataFields() as $field) {
//if the field type has some special specific specification for validation of itself
$validationFunc = $field->jsValidation();
if($validationFunc) $js .= $validationFunc . "\n";
}
$useLabels = $this->useLabels ? 'true' : 'false';
if($this->required) {
foreach($this->required as $field) {
if($fields->dataFieldByName($field)) {
//$js .= "\t\t\t\t\trequire('$field', false, $useLabels);\n";
$js .= <<form->Fields();
foreach($fields as $field) {
$valid = ($field->validate($this) && $valid);
}
if($this->required) {
foreach($this->required as $fieldName) {
$formField = $fields->dataFieldByName($fieldName);
if($formField && !$data[$fieldName]) {
$this->validationError(
$fieldName,
sprintf(
_t('Form.FIELDISREQUIRED'),
strip_tags($formField->Title())
),
"required"
);
$valid = false;
}
}
}
return $valid;
}
/**
* Add's a single required field to requiredfields stack
*/
function addRequiredField( $field ) {
$this->required[] = $field;
}
function removeRequiredField($field) {
for($i=0; $irequired); $i++) {
if($field == $this->required[$i]) {
unset($this->required[$i]);
}
}
}
/**
* allows you too add more required fields to this object after construction.
*/
function appendRequiredFields($requiredFields){
$this->required = array_merge($this->required,$requiredFields->getRequired());
}
/**
* Returns true if the named field is "required".
* Used by FormField to return a value for FormField::Required(), to do things like show *s on the form template.
*/
function fieldIsRequired($fieldName) {
return in_array($fieldName, $this->required);
}
/**
* getter function for append
*/
function getRequired(){
return $this->required;
}
}
?>