public function testOptgroups() { $select = Builder::select()->optgroups(['Numbers' => [0 => 'Zero', 1 => 'One', 2 => 'Two'], 'Letters' => ['a' => 'A', 'b' => 'B', 'c' => 'C']]); $this->assertCount(6, $select); $select->options([3 => 'Three']); $this->assertCount(7, $select); $select->clear()->options([4 => 'Four']); $this->assertCount(1, $select); }
/** * @depends testBase */ public function testFields(Form $form) { $form->add(['name' => Builder::text()->maxlength(50)->required()->label('Your name'), 'email' => Builder::email()->required()->label('Your email'), 'telephone' => Builder::tel()->required()->label('Telephone number'), 'avatar' => Builder::file()->required()->label('Avatar'), 'gender' => Builder::choose(['m' => Builder::radio()->label('Male'), 'f' => Builder::radio()->required()->label('Female')]), 'born' => Builder::group(['day' => Builder::number()->required()->min(1)->max(31)->label('Day'), 'month' => Builder::number()->required()->min(1)->max(12)->label('Month'), 'year' => Builder::number()->required()->min(1900)->max(2013)->label('Year')]), 'language' => Builder::select()->required()->options(array('gl' => 'Galician', 'es' => 'Spanish', 'en' => 'English'))->label('Language'), 'friends' => Builder::collection(['name' => Builder::text()->required()->label('Name'), 'email' => Builder::email()->required()->label('email'), 'age' => Builder::number()->required()->label('Age')]), 'action' => Builder::choose(['save' => Builder::submit()->html('Save changes'), 'duplicate' => Builder::submit()->html('Save as new value')])]); $this->assertCount(9, $form); $this->assertInstanceOf('FormManager\\Fields\\Text', $form['name']); $this->assertInstanceOf('FormManager\\Fields\\Submit', $form['action']['save']); $this->assertSame($form, $form['action']['save']->getForm()); return $form; }
<?php require __DIR__ . '/src/autoloader.php'; ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('log_errors', 1); ini_set('error_log', __DIR__ . '/php.log'); use FormManager\Builder as F; use FormManager\InvalidValueException; $form = F::Form(['data' => F::group(['dia' => F::number()->label('Dia'), 'mes' => F::number()->label('Mes')]), 'colores' => F::choose(['red' => F::radio()->label('Red'), 'blue' => F::radio()->label('Blue'), 'green' => F::radio()->label('Green')]), 'personas' => F::collection(['nome' => F::text()->label('Nome'), 'apelido' => F::text()->label('Apelidos')]), 'bloques' => F::collectionMultiple(['texto' => ['titulo' => F::text()->label('Titulo'), 'texto' => F::textarea()->label('Texto')], 'cita' => ['texto' => F::textarea()->label('Texto'), 'autor' => F::text()->label('Autor')]]), 'enviar' => F::submit()->html('Enviar')]); $form->fieldsets(['personal' => ['nome' => F::text()->label('O teu nome')->addValidator(function ($input) { if ($input->val() !== 'Lolo') { throw new InvalidValueException('Nome non valido, debe ser Lolo'); } })->datalist(['Lolo' => 'Lolo', 'Manolo' => 'Manolo']), 'apelido' => F::text()->label('O teu apelido'), 'idade' => F::select()->options([1 => 'Menor de idade', 2 => 'Maiore de idade'])->label('Idade')->render(function ($input) { return '<p>' . $input . '</p>'; })]]); $form['nome']->errorLabel->class('my-error'); $form->loadFromGlobals(); if (!$form->isValid()) { echo 'Invalid values'; } echo $form;
public function loadIndexAdvanced(array $options) { $filters = B::collection(['f-search-f' => B::select()->options($options), 'f-search-q' => B::search()->attr(['placeholder' => __('Search')])]); return $this->method('get')->add(['filters' => $filters, 'f-rows' => B::hidden(), 'f-sort' => B::hidden()])->setRender('Bootstrap'); }