From 56fbe55a47d1b7757c89d0a0a4a72fe5610949ee Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 28 Apr 2009 23:55:53 +0000 Subject: [PATCH] Merged from branches/2.3 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75580 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- api/SapphireSoapServer.php | 2 +- core/model/RedirectorPage.php | 3 ++ core/model/fieldtypes/DBField.php | 11 +++++++- css/ComplexTableField.css | 7 +++++ dev/FunctionalTest.php | 4 +-- forms/ConfirmedPasswordField.php | 2 ++ forms/CurrencyField.php | 4 +-- forms/FieldSet.php | 12 ++++---- forms/FormField.php | 28 +++++++++++++++++++ forms/NumericField.php | 4 +-- forms/PasswordField.php | 6 ++-- forms/RequiredFields.php | 13 +++++---- forms/ResetFormAction.php | 46 ++++++++++++------------------- forms/SimpleImageField.php | 7 +++-- templates/TableListField.ss | 4 +-- 15 files changed, 99 insertions(+), 54 deletions(-) diff --git a/api/SapphireSoapServer.php b/api/SapphireSoapServer.php index aa75fcf60..73e902f96 100755 --- a/api/SapphireSoapServer.php +++ b/api/SapphireSoapServer.php @@ -63,7 +63,7 @@ class SapphireSoapServer extends Controller { fwrite($fh, $wsdl); fclose($fh); - $s = new SoapServer($wsdlFile); + $s = new SoapServer($wsdlFile, array('cache_wsdl' => WSDL_CACHE_NONE)); $s->setClass($this->class); $s->handle(); } diff --git a/core/model/RedirectorPage.php b/core/model/RedirectorPage.php index 34337785d..a8f117e81 100755 --- a/core/model/RedirectorPage.php +++ b/core/model/RedirectorPage.php @@ -1,11 +1,14 @@ value)); - } + } + + /** + * Converts the current value for this Enum DBField to uppercase. + * @return string + */ + function UpperCase() { + return Convert::raw2xml(strtoupper($this->value)); + } + /** * Returns the value to be set in the database to blank this field. diff --git a/css/ComplexTableField.css b/css/ComplexTableField.css index 2e51cb417..0480a41cf 100755 --- a/css/ComplexTableField.css +++ b/css/ComplexTableField.css @@ -21,6 +21,13 @@ font-size: 11px; } +/* popup */ +.ComplexTableField_ItemRequest_Popup { + height: 100%; + overflow: auto; +} + +/* table */ .ComplexTableField { margin-bottom: 10px; } diff --git a/dev/FunctionalTest.php b/dev/FunctionalTest.php index e89e06b63..45ee853c7 100644 --- a/dev/FunctionalTest.php +++ b/dev/FunctionalTest.php @@ -153,7 +153,7 @@ class FunctionalTest extends SapphireTest { foreach($expectedMatches as $match) { if(!isset($actuals[$match])) { throw new PHPUnit_Framework_AssertionFailedError( - "Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n" + "Failed asserting the CSS selector '$selector' has a partial match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n" . "Instead the following elements were found:\n'" . implode("'\n'", array_keys($actuals)) . "'" ); return false; @@ -217,7 +217,7 @@ class FunctionalTest extends SapphireTest { foreach($expectedMatches as $match) { if(!isset($actuals[$match])) { throw new PHPUnit_Framework_AssertionFailedError( - "Failed asserting the CSS selector '$selector' has an exact match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n" + "Failed asserting the CSS selector '$selector' has a partial match to the expected elements:\n'" . implode("'\n'", $expectedMatches) . "'\n\n" . "Instead the following elements were found:\n'" . implode("'\n'", array_keys($actuals)) . "'" ); return false; diff --git a/forms/ConfirmedPasswordField.php b/forms/ConfirmedPasswordField.php index 530e2a732..b933c11db 100644 --- a/forms/ConfirmedPasswordField.php +++ b/forms/ConfirmedPasswordField.php @@ -117,6 +117,8 @@ class ConfirmedPasswordField extends FormField { } foreach($this->children as $field) { + $field->setDisabled($this->isDisabled()); + $field->setReadonly($this->isReadonly()); $content .= $field->FieldHolder(); } diff --git a/forms/CurrencyField.php b/forms/CurrencyField.php index 90cacb258..90d9ad328 100755 --- a/forms/CurrencyField.php +++ b/forms/CurrencyField.php @@ -53,7 +53,7 @@ Behaviour.register({ if(!el || !el.value) return true; var value = \$F(el); - if(value.length > 0 && !value.match(/^\\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?\$/)) { + if(value.length > 0 && !value.match(/^\s*\\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?\s*\$/)) { validationError(el,"$error","validation",false); return false; } @@ -71,7 +71,7 @@ JS; } function validate($validator) { - if(!empty ($this->value) && !preg_match('/^\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/', $this->value)) { + if(!empty ($this->value) && !preg_match('/^\s*\$?(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?\s*$/', $this->value)) { $validator->validationError($this->name, _t('Form.VALIDCURRENCY', "Please enter a valid currency."), "validation", false); return false; } diff --git a/forms/FieldSet.php b/forms/FieldSet.php index 350cd3dfa..17ac28551 100755 --- a/forms/FieldSet.php +++ b/forms/FieldSet.php @@ -172,11 +172,13 @@ class FieldSet extends DataObjectSet { } foreach($this->items as $i => $child) { - if(is_object($child) && ($child->Name() == $fieldName || $child->Title() == $fieldName) && (!$dataFieldOnly || $child->hasData())) { - array_splice( $this->items, $i, 1 ); - break; - } else if($child->isComposite()) { - $child->removeByName($fieldName, $dataFieldOnly); + if(is_object($child)){ + if(($child->Name() == $fieldName || $child->Title() == $fieldName) && (!$dataFieldOnly || $child->hasData())) { + array_splice( $this->items, $i, 1 ); + break; + } else if($child->isComposite()) { + $child->removeByName($fieldName, $dataFieldOnly); + } } } } diff --git a/forms/FormField.php b/forms/FormField.php index 86679665c..5c71912dc 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -58,6 +58,11 @@ class FormField extends RequestHandler { */ protected $disabled = false; + /** + * @var Custom Validation Message for the Field + */ + protected $customValidationMessage = ""; + /** * Create a new field. * @param name The internal field name, passed to forms. @@ -309,6 +314,29 @@ class FormField extends RequestHandler { $this->messageType = $messageType; } + /** + * Set the custom error message to show instead of the default + * format of Please Fill In XXX. Different from setError() as + * that appends it to the standard error messaging + * + * @param String Message for the error + */ + public function setCustomValidationMessage($msg) { + $this->customValidationMessage = $msg; + } + + /** + * Get the custom error message for this form field. If a custom + * message has not been defined then just return blank. The default + * error is defined on {@link Validator}. + * + * @todo Should the default error message be stored here instead + * @return String + */ + public function getCustomValidationMessage() { + return $this->customValidationMessage; + } + /** * Returns the form field - used by templates. * Although FieldHolder is generally what is inserted into templates, all of the field holder diff --git a/forms/NumericField.php b/forms/NumericField.php index 2eed0d4df..ea36d79f5 100755 --- a/forms/NumericField.php +++ b/forms/NumericField.php @@ -17,7 +17,7 @@ Behaviour.register({ el = _CURRENT_FORM.elements[fieldName]; if(!el || !el.value) return true; - if(el.value.match(/^([0-9]+(\.[0-9]+)?$)/)) { + if(el.value.match(/^\s*([0-9]+(\.[0-9]+)?\s*$)/)) { return true; } else { validationError(el, "'" + el.value + "' $error","validation"); @@ -43,7 +43,7 @@ JS; /** PHP Validation **/ function validate($validator){ - if($this->value && !is_numeric($this->value)){ + if($this->value && !is_numeric(trim($this->value))){ $validator->validationError( $this->name, sprintf( diff --git a/forms/PasswordField.php b/forms/PasswordField.php index 2df9000a1..f2165a93a 100755 --- a/forms/PasswordField.php +++ b/forms/PasswordField.php @@ -25,13 +25,15 @@ class PasswordField extends FormField { function Field() { + $disabled = $this->isDisabled()?"disabled=\"disabled\"":""; + $readonly = $this->isReadonly()?"readonly=\"readonly\"":""; if($this->maxLength) { return "id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . - "\" maxlength=\"$this->maxLength\" size=\"$this->maxLength\"/>"; + "\" maxlength=\"$this->maxLength\" size=\"$this->maxLength\" $disabled $readonly />"; } else { return "id() . - "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" />"; + "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" $disabled $readonly />"; } } diff --git a/forms/RequiredFields.php b/forms/RequiredFields.php index d2c3c9b5e..6c0602118 100755 --- a/forms/RequiredFields.php +++ b/forms/RequiredFields.php @@ -5,10 +5,12 @@ * Submit an array of arguments or each field as a * seperate argument. Validation is performed on a name by * name basis. + * * @package forms * @subpackage validators */ -class RequiredFields extends Validator{ +class RequiredFields extends Validator { + protected $required; protected $useLabels = true; @@ -99,12 +101,13 @@ JS; foreach($this->required as $fieldName) { $formField = $fields->dataFieldByName($fieldName); if($formField && !$data[$fieldName]) { + $errorMessage = sprintf(_t('Form.FIELDISREQUIRED').'.', strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"')); + if($msg = $formField->getCustomValidationMessage()) { + $errorMessage = $msg; + } $this->validationError( $fieldName, - sprintf( - _t('Form.FIELDISREQUIRED').'.', - strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"') - ), + $errorMessage, "required" ); $valid = false; diff --git a/forms/ResetFormAction.php b/forms/ResetFormAction.php index 6dcf64054..e2f7cba31 100755 --- a/forms/ResetFormAction.php +++ b/forms/ResetFormAction.php @@ -8,37 +8,25 @@ class ResetFormAction extends FormAction { function Field() { - if($this->useButtonTag) { - $attributes = array( - 'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''), - 'id' => $this->id(), - 'type' => 'reset', - 'name' => $this->action - ); + $attributes = array( + 'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''), + 'id' => $this->id(), + 'type' => 'reset', + 'name' => $this->action, + ); - if($this->isReadonly()) { - $attributes['disabled'] = 'disabled'; - $attributes['class'] = $attributes['class'] . ' disabled'; - } - - return $this->createTag('button', $attributes, $this->attrTitle()); - } else { - $attributes = array( - 'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''), - 'id' => $this->id(), - 'type' => 'reset', - 'name' => $this->action, - ); - - if($this->isReadonly()) { - $attributes['disabled'] = 'disabled'; - $attributes['class'] = $attributes['class'] . ' disabled'; - } - - $attributes['title'] = ($this->description) ? $this->description : ($this->dontEscape) ? $this->Title() : $this->attrTitle(); - - return $this->createTag('input', $attributes); + if($this->isReadonly()) { + $attributes['disabled'] = 'disabled'; + $attributes['class'] = $attributes['class'] . ' disabled'; } + + $attributes['title'] = ($this->description) ? $this->description : ($this->dontEscape) ? $this->Title() : $this->attrTitle(); + + if($this->useButtonTag) { + return $this->createTag('button', $attributes, $this->attrTitle()); + } + + return $this->createTag('input', $attributes); } } diff --git a/forms/SimpleImageField.php b/forms/SimpleImageField.php index 2caf1fe62..90e1d2fa3 100755 --- a/forms/SimpleImageField.php +++ b/forms/SimpleImageField.php @@ -24,9 +24,9 @@ class SimpleImageField extends FileField { public $allowedExtensions = array('jpg','gif','png'); function Field() { - $record = $this->form->getRecord(); + if($this->form) $record = $this->form->getRecord(); $fieldName = $this->name; - if($record) { + if(isset($record)&&$record) { $imageField = $record->$fieldName(); } else { $imageField = ""; @@ -47,7 +47,8 @@ class SimpleImageField extends FileField { "type" => "file", "name" => $this->name, "id" => $this->id(), - "tabindex" => $this->getTabIndex() + "tabindex" => $this->getTabIndex(), + 'disabled' => $this->disabled ) ); $html .= $this->createTag("input", diff --git a/templates/TableListField.ss b/templates/TableListField.ss index 59bd2b228..6ef2b87ae 100755 --- a/templates/TableListField.ss +++ b/templates/TableListField.ss @@ -63,7 +63,7 @@ <% else %> <% if Markable %> <% end_if %> - <% _t('NOITEMSFOUND', 'No items found') %> + <% _t('NOITEMSFOUND','No items found') %> <% if Can(delete) %> <% end_if %> <% end_if %> @@ -78,4 +78,4 @@ $Title <% end_control %> - \ No newline at end of file +