Exemple #1
0
 public function testSetFieldDescription()
 {
     $spec = new FormSpec();
     $this->assertTrue($spec->getFieldDescription('wow')->isNothing());
     $final = $spec->withFieldDescription('wow', 'WOWs');
     $this->assertNotSame($spec, $final);
     $this->assertTrue($final->getFieldDescription('wow')->isJust());
     $this->assertEquals('WOWs', Maybe::fromJust($final->getFieldDescription('wow')));
     $this->assertEquals(['wow' => 'WOWs'], $final->getDescriptions()->toArray());
 }
 /**
  * Render the object into a string.
  *
  * @return mixed
  */
 public function render()
 {
     $addColon = function ($label) {
         return Maybe::just(vsprintf('%s:', [$label]));
     };
     return (new Form($this->attributes, $this->spec->getAnnotations()->map(function ($_, $key) use($addColon) {
         return new Row(['class' => 'form-group'], [new Node('label', ['class' => 'col-sm-2 form-control-label'], Maybe::fromMaybe('', $this->spec->getFieldLabel($key)->bind($addColon))), new Div(['class' => 'col-sm-8'], $this->renderFullField($key))]);
     })->append(ArrayMap::of([new Row(['class' => 'form-group'], [new Div(['class' => 'col-sm-offset-2 col-sm-10'], [new Div(['class' => 'btn-group'], [new Button(['type' => 'reset', 'class' => 'btn btn-secondary'], 'Reset'), new Button(['type' => 'submit', 'class' => 'btn btn-primary'], 'Submit')])])])]))))->render();
 }