- Fixed invalid elements after testing

This commit is contained in:
mcndave committed 2019-10-04 08:39:22 -04:00
1 parent a0bf505377
commit 4bf08def27
5 files changed
+73 -68

No files matched your search

+29 -34
View File
@@ -4,12 +4,14 @@ namespace Picea\Ui\Form;
use Picea\Ui\Common\UiElement;
use Picea\Extension\Extension;
use Picea\Extension\ExtensionTrait;
class UiForm extends UiElement implements Extension {
use ExtensionTrait;
public string $defaultMethod = "get";
public string $token = "ui.form";
public array $token = [ "ui.form", "ui.endform", "ui.form.get", "ui.form.post" ];
public string $tag = "form";
@@ -19,40 +21,33 @@ class UiForm extends UiElement implements Extension {
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string
{
list($action, $options) = array_pad(explode(',', $arguments), 2, null);
switch($token) {
case "ui.form.get":
$this->attributes['method'] = "get";
break;
case "ui.form.post":
$this->attributes['method'] = "post";
break;
default:
case $this->token:
$this->attributes['method'] = $this->defaultMethod;
break;
}
$this->attributes['action'] = $action;
$this->attributes($this->parseAttributes($options));
return $this->render();
}
protected function parseAttributes(string $options) : array
{
if ( $options ?? false ) {
$attributes = eval($options);
if ( ! is_array($attributes) ) {
throw new InvalidArgumentException("Given options `$options` is not a valid attributes array.");
}
return $attributes;
if ( $token === 'ui.endform' ) {
return "</form>";
}
return [];
list($action, $options) = array_pad(explode(',', $arguments), 2, null);
$action = $this->trim($action);
switch($token) {
case "ui.form.get":
$this->attributes['method'] = "get";
break;
case "ui.form.post":
$this->attributes['method'] = "post";
$this->attributes['enctype'] = "multipart/form-data";
break;
default:
case $this->token:
$this->attributes['method'] = $this->defaultMethod;
break;
}
$this->option('tag-type', 'single');
$this->attributes['action'] = $this->trim($action);
$this->attributes($this->parseOptions($options));
return $this->render();
}
}