Only name and tag are mandatory, then other values depending on the tag
function($cfg)
{
if ( \is_string($cfg) ){
$cfg = [
'field' => 'text',
'attr' => [
'name' => $cfg
]
];
}
parent::__construct($cfg);
if ( $this->tag ){
$mandatory_attr = [];
if ( !isset($this->attr['id']) ){
$this->attr['id'] = bbn\Str::genpwd(20,15);
}
$this->script = isset($cfg['script']) ? $cfg['script'] : '';
$this->value = isset($cfg['value']) ? $cfg['value'] : '';
switch ( $this->tag )
{
case "input":
array_push($mandatory_attr, "type");
break;
case "textarea":
array_push($mandatory_attr, "cols", "rows");
break;
case "select":
array_push($mandatory_attr, "attr");
break;
}
foreach ( $mandatory_attr as $m ){
if ( !isset($this->attr[$m]) ){
die("Argument $m is missing in your config... Sorry!");
}
}
}
return $this;
}