Commit 19fefdf8 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Clientside validator implemented via Bootstrap Validator.

Support.php: PhpDoc
AbstractBuildForm.php: extended buildRow* with parameter htmlFormElementId. buildLabel rewritten to use Support::doAttribute, Support::wrapTag. buildInput/buildDateTim,buildSelect() now add's class 'form-control'. Input fields now offers a 'help-block'-div
BuildFormBootstrap, BuildFormPlain.php, BuildFormTable.php: buildRowNative rewritten to support <label>. Signature of BuildRow* adjusted
parent 3c0b15fd
......@@ -385,7 +385,7 @@ abstract class AbstractBuildForm {
// Construct Marshaller Name: buildRow
$buildRowName = 'buildRow' . $this->buildRowName[$formElement['type']];
$html .= $this->$buildRowName($formElement, $elementHtml);
$html .= $this->$buildRowName($formElement, $elementHtml, $htmlFormElementId);
// break;
}
......@@ -473,23 +473,26 @@ abstract class AbstractBuildForm {
return $url;
}
abstract public function buildRowNative($formElement, $elementHtml);
abstract public function buildRowNative(array $formElement, $htmlElement, $htmlFormElementId);
abstract public function buildRowPill($formElement, $elementHtml);
abstract public function buildRowPill(array $formElement, $elementHtml);
abstract public function buildRowFieldset($formElement, $elementHtml);
abstract public function buildRowFieldset(array $formElement, $elementHtml);
abstract public function buildRowSubrecord($formElement, $elementHtml);
abstract public function buildRowSubrecord(array $formElement, $elementHtml);
/**
* Builds a label, typically for an html-'<input>'-element.
*
* @param array $htmlFormElementId
* @param $label
* @param string $htmlFormElementId
* @param string $label
* @return string
*/
public function buildLabel($htmlFormElementId, $label) {
$html = '<label for="' . $htmlFormElementId . '">' . $label . '</label>';
$attributes = Support::doAttribute('for', $htmlFormElementId);
$attributes .= Support::doAttribute('class', 'control-label');
$html = Support::wrapTag("<label $attributes>", $label);
return $html;
}
......@@ -511,6 +514,7 @@ abstract class AbstractBuildForm {
$textarea = '';
$attribute = Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control');
// Check for input type 'textarea'
$colsRows = explode(',', $formElement['size'], 2);
......@@ -548,7 +552,7 @@ abstract class AbstractBuildForm {
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
return "$htmlTag $attribute>$textarea";
return "$htmlTag $attribute>$textarea" . $this->getHelpBlock();
}
......@@ -727,6 +731,13 @@ abstract class AbstractBuildForm {
return $attribute;
}
/**
* @return string
*/
private function getHelpBlock() {
return '<div class="help-block with-errors"></div>';
}
/**
* Builds HTML 'checkbox' element.
*
......@@ -1133,6 +1144,7 @@ abstract class AbstractBuildForm {
$attribute = $this->getAttributeMode($formElement);
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control');
$attribute .= Support::doAttribute('title', $formElement['tooltip']);
$attribute .= $this->getAttributeList($formElement, ['autofocus']);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
......@@ -1166,7 +1178,7 @@ abstract class AbstractBuildForm {
$json = $this->getJsonElementUpdate($htmlFormElementId, $jsonValues, $formElement['mode']);
return '<select ' . $attribute . '>' . $option . '</select>';
return '<select ' . $attribute . '>' . $option . '</select>' . $this->getHelpBlock();
}
/**
......@@ -1492,15 +1504,16 @@ abstract class AbstractBuildForm {
public function buildFile(array $formElement, $htmlFormElementId, $value, &$json) {
$attribute = $this->getAttributeMode($formElement);
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control');
$attribute .= Support::doAttribute('type', 'file');
$attribute .= Support::doAttribute('title', $formElement['tooltip']);
$attribute .= Support::doAttribute('name', $htmlFormElementId);
$attribute .= $this->getAttributeList($formElement, ['autofocus', 'accept']);
$attribute .= Support::doAttribute('data-load', ($formElement['dynamicUpdate'] === 'yes') ? 'data-load' : '');
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
return '<input ' . $attribute . '>';
return '<input ' . $attribute . '>' . $this->getHelpBlock();
}
/**
......@@ -1573,6 +1586,8 @@ abstract class AbstractBuildForm {
public function buildDateTime(array $formElement, $htmlFormElementId, $value, &$json) {
$attribute = Support::doAttribute('name', $htmlFormElementId);
$attribute .= Support::doAttribute('class', 'form-control');
$arrMinMax = null;
$this->adjustMaxLength($formElement);
......@@ -1649,7 +1664,7 @@ abstract class AbstractBuildForm {
$json = $this->getJsonElementUpdate($htmlFormElementId, $value, $formElement['mode']);
return "<input $attribute>";
return "<input $attribute>" . $this->getHelpBlock();
}
......
......@@ -10,7 +10,6 @@ namespace qfq;
use qfq;
use qfq\UserFormException;
use TYPO3\CMS\Form\Domain\Model\Element\ButtonElement;
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/helper/OnArray.php');
......@@ -287,6 +286,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
$attribute = $this->getFormTagAtrributes();
$attribute['class'] = 'form-horizontal';
$attribute['data-toggle'] = 'validator';
return '<form ' . OnArray::toString($attribute, '=', ' ', "'") . '>';
}
......@@ -361,15 +361,17 @@ EOF;
}
/**
* @param $formElement
* @param $elementHtml
* @param array $formElement
* @param string $htmlElement
* @return string
*/
public function buildRowNative($formElement, $elementHtml) {
public function buildRowNative(array $formElement, $htmlElement, $htmlFormElementId) {
$html = '';
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $elementHtml);
$htmlLabel = $this->buildLabel($htmlFormElementId, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $htmlLabel);
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $htmlElement);
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note'], true);
$html = $this->wrapItem(WRAP_SETUP_ELEMENT, $html);
......@@ -382,7 +384,7 @@ EOF;
* @param $elementHtml
* @return string
*/
public function buildRowPill($formElement, $elementHtml) {
public function buildRowPill(array $formElement, $elementHtml) {
$html = '';
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $elementHtml);
......@@ -400,7 +402,7 @@ EOF;
* @param $formElement
* @param $elementHtml
*/
public function buildRowFieldset($formElement, $elementHtml) {
public function buildRowFieldset(array $formElement, $elementHtml) {
}
/**
......@@ -408,7 +410,7 @@ EOF;
* @param $elementHtml
* @return string
*/
public function buildRowSubrecord($formElement, $elementHtml) {
public function buildRowSubrecord(array $formElement, $elementHtml) {
$html = '';
$html .= $this->wrapItem(WRAP_SETUP_ELEMENT, $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['label']));
$html .= $this->wrapItem(WRAP_SETUP_ELEMENT, $this->wrapItem(WRAP_SETUP_SUBRECORD, $elementHtml));
......
......@@ -63,7 +63,7 @@ class BuildFormPlain extends AbstractBuildForm {
* @param $value
* @return string
*/
public function buildRowNative($formElement, $elementHtml) {
public function buildRowNative(array $formElement, $htmlElement, $htmlFormElementId) {
$html = '';
// Construct Marshaller Name
......@@ -73,7 +73,7 @@ class BuildFormPlain extends AbstractBuildForm {
if($formElement['nestedInFieldSet']==='no')
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $elementHtml);
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $htmlElement);
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
if($formElement['nestedInFieldSet']==='no')
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
......@@ -98,15 +98,15 @@ class BuildFormPlain extends AbstractBuildForm {
}
public function buildRowPill($formElement, $elementHtml) {
public function buildRowPill(array $formElement, $elementHtml) {
// TODO: Implement buildRowPill() method.
}
public function buildRowFieldset($formElement, $elementHtml) {
public function buildRowFieldset(array $formElement, $elementHtml) {
// TODO: Implement buildRowFieldset() method.
}
public function buildRowSubrecord($formElement, $elementHtml) {
public function buildRowSubrecord(array $formElement, $elementHtml) {
// TODO: Implement buildRowSubrecord() method.
}
}
\ No newline at end of file
......@@ -90,7 +90,7 @@ class BuildFormTable extends AbstractBuildForm {
* @param $value
* @return string
*/
public function buildRowNative($formElement, $elementHtml) {
public function buildRowNative(array $formElement, $htmlElement, $htmlFormElementId) {
$html = '';
// Construct Marshaller Name
......@@ -99,18 +99,18 @@ class BuildFormTable extends AbstractBuildForm {
if ($formElement['type'] === 'subrecord') {
// subrecord in render='table' are outside the table
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $elementHtml);
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $htmlElement);
$html .= $this->wrapItem(WRAP_SETUP_SUBRECORD, $formElement['note']);
} else {
if ($formElement['nestedInFieldSet'] === 'no') {
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_START];
$html .= $this->wrapItem(WRAP_SETUP_LABEL, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $elementHtml);
$html .= $this->wrapItem(WRAP_SETUP_INPUT, $htmlElement);
$html .= $this->wrapItem(WRAP_SETUP_NOTE, $formElement['note']);
$html .= $this->wrap[WRAP_SETUP_ELEMENT][WRAP_SETUP_END];
} else {
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['label']);
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $elementHtml);
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $htmlElement);
if($formElement['note']!=='')
$html .= $this->wrapItem(WRAP_SETUP_IN_FIELDSET, $formElement['note']);
}
......@@ -138,15 +138,15 @@ class BuildFormTable extends AbstractBuildForm {
return $html;
}
public function buildRowPill($formElement, $elementHtml) {
public function buildRowPill(array $formElement, $elementHtml) {
// TODO: Implement buildRowPill() method.
}
public function buildRowFieldset($formElement, $elementHtml) {
public function buildRowFieldset(array $formElement, $elementHtml) {
// TODO: Implement buildRowFieldset() method.
}
public function buildRowSubrecord($formElement, $elementHtml) {
public function buildRowSubrecord(array $formElement, $elementHtml) {
// TODO: Implement buildRowSubrecord() method.
}
}
\ No newline at end of file
......@@ -61,7 +61,7 @@ class Support {
}
/**
* Extract Tag from $tag (might contain further attributes) and wrap it around $value. If $flagOmitEmpty==true && $value=='': return ''.
* Extract Tag from $tag (eg: <input class="form-control">, might contain further attributes) and wrap it around $value. If $flagOmitEmpty==true && $value=='': return ''.
*
* @param $tag
* @param $value
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment