Ejemplo n.º 1
0
 public function renderField($field, $error)
 {
     $id = $field->getId();
     $label = $field->getLabel();
     $content = static::fieldContent($field);
     $hint = $field->getHint();
     $required = $field->attribute('required');
     /* addons */
     list($prefix, $suffix) = $field->getAddons();
     $have_addon = (bool) ($prefix || $suffix);
     if ($prefix) {
         $prefix = "<div class=\"input-group-addon\">{$prefix}</div>";
     }
     if ($suffix) {
         $suffix = "<div class=\"input-group-addon\">{$suffix}</div>";
     }
     $class = ['form-group'];
     if ($error) {
         $class[] = 'has-error';
         $hint = $hint ? "{$hint}<br/>{$error}" : $error;
     }
     if ($required) {
         $class[] = 'required';
     }
     $group_attr = FormUtils::serializeAttr(['class' => $class]);
     if ($field instanceof FormCheckbox) {
         echo "<div class=\"checkbox\">";
         echo "\t<label for=\"{$id}\" class=\"control-label\">";
         echo "\t\t{$content}";
         echo "\t\t{$field->getText()}";
         echo "\t</label>";
         if ($hint) {
             echo "\t<span class=\"help-block\">{$hint}</span>";
         }
         echo '</div>';
         return;
     }
     echo "<div {$group_attr}>";
     if ($label) {
         echo "\t<label for=\"{$id}\" class=\"control-label\">{$label}</label>";
     }
     if ($have_addon) {
         echo "\t<div class=\"input-group\">{$prefix}{$content}{$suffix}</div>";
     } else {
         echo "\t{$content}";
     }
     if ($hint) {
         echo "\t<span class=\"help-block\">{$hint}</span>";
     }
     echo '</div>';
 }
Ejemplo n.º 2
0
 public function renderField($field, $error)
 {
     $this->begin();
     $id = $field->getId();
     $label = $field->getLabel();
     $content = $field->getContent();
     $hint = $field->getHint();
     $hints = $field->layoutHints();
     $required = $field->attribute('required');
     /* prepare classes for row */
     $tr_class = [];
     if ($required) {
         $tr_class[] = 'required';
     }
     if ($error) {
         $tr_class[] = 'have-error';
     }
     $tr_class = FormUtils::serializeAttr(['class' => $tr_class]);
     /* addons */
     list($prefix, $suffix) = $field->getAddons();
     $have_addon = (bool) ($prefix || $suffix);
     if ($prefix) {
         $prefix = "<span class=\"form-prefix\">{$prefix}</span>";
     }
     if ($suffix) {
         $suffix = "<span class=\"form-suffix\">{$suffix}</span>";
     }
     if ($field instanceof FormCheckbox) {
         echo "\t\t<tr {$tr_class}>\n";
         if ($label !== false) {
             echo "\t\t\t<th class=\"form-label\"><label for=\"{$id}\">{$field->getText()}</label></th>\n";
             echo "\t\t\t<td class=\"form-field\">{$content}</td>\n";
             echo "\t\t\t<td class=\"form-hint\">{$hint}</td>\n";
             echo "\t\t\t<td class=\"form-error\">{$error}</td>\n";
         } else {
             echo "\t\t\t<td class=\"form-field\" colspan=\"4\"><label>{$content} {$field->getText()}</label></td>\n";
         }
         echo "\t\t</tr>\n";
         return;
     }
     if (!($hints & Form::LAYOUT_TWOROWS)) {
         echo "\t\t<tr {$tr_class}>\n";
         if ($label !== false) {
             echo "\t\t\t<th class=\"form-label\"><label for=\"{$id}\">{$label}</label></th>\n";
             if ($have_addon) {
                 echo "\t\t\t<td class=\"form-field\"><div class=\"form-addon\">{$prefix}{$content}{$suffix}</div></td>\n";
             } else {
                 echo "\t\t\t<td class=\"form-field\">{$content}</td>\n";
             }
             echo "\t\t\t<td class=\"form-hint\">{$hint}</td>\n";
             echo "\t\t\t<td class=\"form-error\">{$error}</td>\n";
         } else {
             echo "\t\t\t<td class=\"form-field\" colspan=\"4\">{$content}</td>\n";
         }
         echo "\t\t</tr>\n";
     } else {
         if ($hints & Form::LAYOUT_FILL) {
             echo "\t\t<tr {$tr_class}>\n";
             echo "\t\t\t<th class=\"form-label tworow\" colspan=\"2\" valign=\"top\"><label for=\"{$id}\">{$label}</label></th>\n";
             echo "\t\t\t<td class=\"form-hint\"  valign=\"top\">{$hint}</td>\n";
             echo "\t\t\t<td class=\"form-error\" valign=\"top\">{$error}</td>\n";
             echo "\t\t</tr>\n";
             echo "\t\t<tr {$tr_class}>\n";
             echo "\t\t\t<td class=\"form-field\" colspan=\"4\">{$content}</td>\n";
             echo "\t\t</tr>\n";
         } else {
             echo "\t\t<tr {$tr_class}>\n";
             echo "\t\t\t<th class=\"form-label tworow\" colspan=\"4\"><label for=\"{$id}\">{$label}</label></th>\n";
             echo "\t\t</tr>\n";
             echo "\t\t<tr {$tr_class}>\n";
             echo "\t\t\t<td class=\"form-field\" valign=\"top\" colspan=\"2\">{$content}</td>\n";
             echo "\t\t\t<td class=\"form-hint\"  valign=\"top\">{$hint}</td>\n";
             echo "\t\t\t<td class=\"form-error\" valign=\"top\">{$error}</td>\n";
             echo "\t\t</tr>\n";
         }
     }
 }
Ejemplo n.º 3
0
 public function testSerializeAttributeEmpyArray()
 {
     $this->assertEquals('', FormUtils::serializeAttr(['foo' => []]));
 }