Merged revisions 47613 via svnmerge from

svn://svn.silverstripe.com/silverstripe/modules/sapphire/branches/2.2.0-mesq

........
  r47613 | ischommer | 2008-01-04 19:14:58 +1300 (Fri, 04 Jan 2008) | 1 line
  
  adding tabIndex capabilities, switching HTML-rendering to createTag()
........


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@52199 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-04-06 04:08:45 +00:00
parent cb860c2f75
commit 9e98f127f2
15 changed files with 97 additions and 42 deletions

View File

@ -25,7 +25,13 @@ class AjaxFormAction extends FormAction {
parent::__construct($action, $title, $form); parent::__construct($action, $title, $form);
} }
function Field() { function Field() {
return "<input class=\"ajaxAction-$this->ajaxAction action\" id=\"" . $this->id() . "\" type=\"submit\" name=\"{$this->name}\" value=\"{$this->title}\" />"; return $this->createTag('input', array(
'class' => "ajaxAction-$this->ajaxAction action",
'id' => $this->id(),
'type' => 'submit',
'value' => $this->title,
'tabindex' => $this->getTabIndexHTML()
));
} }
function Title() { function Title() {

View File

@ -41,14 +41,20 @@ class AjaxUniqueTextField extends TextField {
$url = Convert::raw2att( $this->validateURL ); $url = Convert::raw2att( $this->validateURL );
if( $this->restrictedRegex ) if($this->restrictedRegex)
$restrict = "<input type=\"hidden\" class=\"hidden\" name=\"{$this->name}Restricted\" id=\"" . $this->id() . "RestrictedRegex\" value=\"{$this->restrictedRegex}\" />"; $restrict = "<input type=\"hidden\" class=\"hidden\" name=\"{$this->name}Restricted\" id=\"" . $this->id() . "RestrictedRegex\" value=\"{$this->restrictedRegex}\" />";
if($this->maxLength) { $attributes = array(
return "<input class=\"".$this->class."\" text\" type=\"text\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" maxlength=\"$this->maxLength\" />$restrict"; 'type' => 'text',
} else { 'class' => $this->extraClass() . " text",
return "<input class=\"".$this->class."\" text\" type=\"text\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" />$restrict"; 'id' => $this->id(),
} 'name' => $this->attrName(),
'value' => $this->attrValue(),
'tabindex' => $this->getTabIndexHTML(),
'maxlength' => ($this->maxLength) ? $this->maxLength : null
);
return $this->createTag('input', $attributes);
} }
function jsValidation() { function jsValidation() {

View File

@ -28,13 +28,18 @@ class AutocompleteTextField extends TextField {
// Requirements::javascript('sapphire/javascript/AutocompleteTextField.js'); // Requirements::javascript('sapphire/javascript/AutocompleteTextField.js');
$extraClass = $this->extraClass(); $extraClass = $this->extraClass();
$fieldSize = $this->maxLength ? min( $this->maxLength, 30 ) : 30; $attributes = array(
'class' => "{$this->class} text",
if($this->maxLength) { 'type' => 'text',
return "<input class=\"text maxlength$extraClass\" type=\"text\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" maxlength=\"$this->maxLength\" size=\"$fieldSize\" /><div id=\"" . $this->id() . "_Options\" class=\"autocompleteoptions\"></div>"; 'id' => $this->id(),
} else { 'name' => $this->name,
return "<input class=\"text$extraClass\" type=\"text\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" /><div id=\"" . $this->id() . "_Options\" class=\"autocompleteoptions\"></div>"; 'value' => $this->attrValue(),
} 'tabindex' => $this->getTabIndexHTML(),
'size' => $this->maxLength ? min( $this->maxLength, 30 ) : 30
);
if($this->maxLength) $attributes['maxlength'] = $this->maxLength;
return $this->createTag('input', $attributes) . "<div id=\"" . $this->id() . "_Options\" class=\"autocompleteoptions\"></div>";
} }
function FieldHolder() { function FieldHolder() {

View File

@ -46,11 +46,17 @@ class BankAccountField extends FormField {
) = explode(" ",$this->value); ) = explode(" ",$this->value);
$valueArr = self::convert_format_nz($valueArr); $valueArr = self::convert_format_nz($valueArr);
$field->push(new NumericField($this->name.'[BankCode]', '', $valueArr['BankCode'], 2)); $field->push($n1 = new NumericField($this->name.'[BankCode]', '', $valueArr['BankCode'], 2));
$field->push(new NumericField($this->name.'[BranchCode]', '', $valueArr['BranchCode'], 4)); $field->push($n2 = new NumericField($this->name.'[BranchCode]', '', $valueArr['BranchCode'], 4));
$field->push(new NumericField($this->name.'[AccountNumber]', '', $valueArr['AccountNumber'], 8)); $field->push($n3 = new NumericField($this->name.'[AccountNumber]', '', $valueArr['AccountNumber'], 8));
$field->push(new NumericField($this->name.'[AccountSuffix]', '', $valueArr['AccountSuffix'], 3)); $field->push($n4 = new NumericField($this->name.'[AccountSuffix]', '', $valueArr['AccountSuffix'], 3));
if($this->tabIndex) {
$n1->setTabIndex($this->getTabIndex());
$n2->setTabIndex($this->getTabIndex()+1);
$n3->setTabIndex($this->getTabIndex()+2);
$n4->setTabIndex($this->getTabIndex()+3);
}
return $field; return $field;
} }

View File

@ -29,7 +29,7 @@ HTML;
Requirements::css("jsparty/calendar/calendar-win2k-1.css"); Requirements::css("jsparty/calendar/calendar-win2k-1.css");
$field = parent::Field(); $field = parent::Field();
$id = $this->id(); $id = $this->id();
$val = $this->attrValue(); $val = $this->attrValue();

View File

@ -20,9 +20,18 @@ class CheckboxField extends FormField {
protected $disabled; protected $disabled;
function Field() { function Field() {
$checked = $this->value ? "checked=\"checked\"" : ''; $attributes = array(
$disabled = $this->disabled ? " disabled=\"disabled\"" : ""; 'type' => 'checkbox',
return "<input class=\"checkbox\" type=\"checkbox\" value=\"1\" id=\"" . $this->id() . "\" name=\"{$this->name}\" $checked $disabled />"; 'class' => $this->extraClass(),
'id' => $this->id(),
'name' => $this->attrName(),
'value' => 1,
'tabindex' => $this->getTabIndexHTML(),
'checked' => $this->value ? "checked=\"checked\"" : '',
'disabled' => $this->disabled ? " disabled=\"disabled\"" : "",
);
return $this->createTag('input', $attributes);
} }

View File

@ -15,11 +15,17 @@ class CheckboxFieldDisabled extends CheckboxField {
* Returns a single checkbox field - used by templates. * Returns a single checkbox field - used by templates.
*/ */
function Field() { function Field() {
$checked = ''; $attributes = array(
if($this->value) 'type' => 'checkbox',
$checked = " checked = \"checked\""; 'class' => $this->extraClass() . " text",
return "<input class=\"checkbox\" disabled=\"disabled\" type=\"checkbox\" id=\"" . 'id' => $this->id(),
$this->id() . "\" name=\"{$this->name}\"$checked />"; 'name' => $this->attrName(),
'tabindex' => $this->getTabIndexHTML(),
'checked' => ($this->value) ? 'checked' : false,
'disabled' => 'disabled'
);
return $this->createTag('input', $attributes);
} }
} }

View File

@ -46,6 +46,9 @@ class CompositeDateField extends DateField {
} }
function Field() { function Field() {
$this->dateDropdown->setTabIndex($this->getTabIndex());
$this->monthDropdown->setTabIndex($this->getTabIndex()+1);
$this->yearDropdown->setTabIndex($this->getTabIndex()+2);
return $this->dateDropdown->Field() . $this->monthDropdown->Field() . $this->yearDropdown->Field(); return $this->dateDropdown->Field() . $this->monthDropdown->Field() . $this->yearDropdown->Field();
} }

View File

@ -26,7 +26,17 @@ class ConfirmedFormAction extends FormAction {
parent::__construct($action, $title, $form); parent::__construct($action, $title, $form);
} }
function Field() { function Field() {
return "<input class=\"action " . $this->extraClass() . "\" id=\"" . $this->id() . "\" type=\"submit\" name=\"{$this->name}\" value=\"{$this->title}\" onclick=\"return confirm('$this->confirmation');\" />"; $attributes = array(
'type' => 'submit',
'class' => $this->extraClass(),
'id' => $this->id(),
'name' => $this->attrName(),
'value' => $this->attrTitle(),
'tabindex' => $this->getTabIndexHTML(),
'onclick' => "return confirm('$this->confirmation');"
);
return $this->createTag('input', $attributes);
} }
} }

View File

@ -89,7 +89,7 @@ class ConfirmedPasswordField extends FormField {
if($this->showOnClick) { if($this->showOnClick) {
$content .= "<div class=\"showOnClick\">\n"; $content .= "<div class=\"showOnClick\">\n";
$content .= "<a href=\"#\">{$this->showOnClickTitle}</a>\n"; $content .= "<a href=\"#\"" . $this->getTabIndexHTML() . ">{$this->showOnClickTitle}</a>\n";
$content .= "<div class=\"showOnClickContainer\">"; $content .= "<div class=\"showOnClickContainer\">";
} }

View File

@ -16,10 +16,10 @@ class CreditCardField extends TextField {
$parts = explode("\n", chunk_split($this->value,4,"\n")); $parts = explode("\n", chunk_split($this->value,4,"\n"));
$parts = array_pad($parts, 4, ""); $parts = array_pad($parts, 4, "");
$field = "<span id=\"{$this->name}_Holder\" class=\"creditCardField\">" . $field = "<span id=\"{$this->name}_Holder\" class=\"creditCardField\">" .
"<input autocomplete=\"off\" name=\"{$this->name}[0]\" value=\"$parts[0]\" maxlength=\"4\" /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[0]\" value=\"$parts[0]\" maxlength=\"4\"" . $this->getTabIndexHTML(0) . " /> - " .
"<input autocomplete=\"off\" name=\"{$this->name}[1]\" value=\"$parts[1]\" maxlength=\"4\" /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[1]\" value=\"$parts[1]\" maxlength=\"4\"" . $this->getTabIndexHTML(1) . " /> - " .
"<input autocomplete=\"off\" name=\"{$this->name}[2]\" value=\"$parts[2]\" maxlength=\"4\" /> - " . "<input autocomplete=\"off\" name=\"{$this->name}[2]\" value=\"$parts[2]\" maxlength=\"4\"" . $this->getTabIndexHTML(2) . " /> - " .
"<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"$parts[3]\" maxlength=\"4\" /></span>"; "<input autocomplete=\"off\" name=\"{$this->name}[3]\" value=\"$parts[3]\" maxlength=\"4\"" . $this->getTabIndexHTML(3) . " /></span>";
return $field; return $field;
} }
function dataValue() { function dataValue() {

View File

@ -46,9 +46,9 @@ class DMYCalendarDateField extends CalendarDateField {
return <<<HTML return <<<HTML
<div class="dmycalendardate"> <div class="dmycalendardate">
<input type="hidden" id="$id" name="{$this->name}" value="$val" /> <input type="hidden" id="$id" name="{$this->name}" value="$val" />
<input type="text" id="$id-day" class="day numeric" name="{$fieldNamePrefix}[{$fieldName}-Day]" value="$day" maxlength="2" />/ <input type="text" id="$id-day" class="day numeric" name="{$fieldNamePrefix}[{$fieldName}-Day]" value="$day" maxlength="2"$tabIndex0 />/
<input type="text" id="$id-month" class="month numeric" name="{$fieldNamePrefix}[{$fieldName}-Month]" value="$month" maxlength="2" />/ <input type="text" id="$id-month" class="month numeric" name="{$fieldNamePrefix}[{$fieldName}-Month]" value="$month" maxlength="2"$tabIndex1 />/
<input type="text" id="$id-year" class="year numeric" name="{$fieldNamePrefix}[{$fieldName}-Year]" value="$year" maxlength="4" /> <input type="text" id="$id-year" class="year numeric" name="{$fieldNamePrefix}[{$fieldName}-Year]" value="$year" maxlength="4"$tabIndex2 />
<div class="calendarpopup" id="{$id}-calendar"></div> <div class="calendarpopup" id="{$id}-calendar"></div>
</div> </div>
HTML; HTML;

View File

@ -49,12 +49,16 @@ class DMYDateField extends CalendarDateField {
$fieldName = $this->name; $fieldName = $this->name;
$tabIndex0 = $this->getTabIndexHTML(0);
$tabIndex1 = $this->getTabIndexHTML(1);
$tabIndex2 = $this->getTabIndexHTML(2);
return <<<HTML return <<<HTML
<div class="dmycalendardate"> <div class="dmycalendardate">
<input type="hidden" id="$id" name="{$this->name}" value="$val" /> <input type="hidden" id="$id" name="{$this->name}" value="$val" />
<input type="text" id="$id-day" class="day numeric" name="{$fieldName}[Day]" value="$day" maxlength="2" />/ <input type="text" id="$id-day" class="day numeric" name="{$fieldName}[Day]" value="$day" maxlength="2"$tabIndex0 />/
<input type="text" id="$id-month" class="month numeric" name="{$fieldName}[Month]" value="$month" maxlength="2" />/ <input type="text" id="$id-month" class="month numeric" name="{$fieldName}[Month]" value="$month" maxlength="2"$tabIndex1 />/
<input type="text" id="$id-year" class="year numeric" name="{$fieldName}[Year]" value="$year" maxlength="4" /> <input type="text" id="$id-year" class="year numeric" name="{$fieldName}[Year]" value="$year" maxlength="4"$tabIndex2 />
<div class="calendarpopup" id="{$id}-calendar"></div> <div class="calendarpopup" id="{$id}-calendar"></div>
</div> </div>
HTML; HTML;

View File

@ -55,7 +55,7 @@ class DropdownField extends FormField {
$id = $this->id(); $id = $this->id();
$disabled = $this->disabled ? " disabled=\"disabled\"" : ""; $disabled = $this->disabled ? " disabled=\"disabled\"" : "";
return "<select $classAttr $disabled name=\"$this->name\" id=\"$id\">$options</select>"; return "<select $classAttr $disabled name=\"$this->name\" id=\"$id\"" . $this->getTabIndexHTML() . ">$options</select>";
} }
function isSelected(){ function isSelected(){

View File

@ -12,7 +12,7 @@
*/ */
class EncryptField extends TextField { class EncryptField extends TextField {
function Field() { function Field() {
return "<input class=\"text\" type=\"password\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" />"; return "<input class=\"text\" type=\"password\" id=\"" . $this->id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\"" . $this->getTabIndexHTML() . " />";
} }
} }