for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace Formularium\Frontend\HTMLValidation;
use Formularium\Field;
use Formularium\HTMLNode;
use Formularium\Validator\MaxLength;
use Formularium\Validator\MinLength;
use Formularium\Validator\Regex;
class Renderable extends \Formularium\Renderable
{
public function viewable($value, Field $field, HTMLNode $previous): HTMLNode
return $previous;
}
public function editable($value, Field $field, HTMLNode $previous): HTMLNode
$validators = $field->getValidators();
$element = $this->getInput($previous);
if (!$element) {
$element
Formularium\HTMLNode
true
$datatype = $field->getDatatype();
$datatype
foreach ($validators as $validator => $data) {
switch ($validator) {
case MinLength::class:
$element->setAttribute('minlength', $field->getValidatorOption($validator, 'value', ''));
break;
case MaxLength::class:
$element->setAttribute('maxlength', $field->getValidatorOption($validator, 'value', ''));
case Regex::class:
$element->setAttribute('pattern', $field->getValidatorOption($validator, 'value', ''));
default:
protected function getInput(HTMLNode $previous): ?HTMLNode
/**
* @var HTMLNode $element
*/
$element = null;
$input = $previous->get('input');
if (count($input)) {
return $input[0];
$input = $previous->get('textarea');
$element = $input[0];
return $element;