Beispiel #1
0
 public function testCollectionField()
 {
     $field = Field::collection(['name' => Field::text()->label('Name'), 'email' => Field::email()->label('email'), 'age' => Field::number()->label('Age'), 'image' => Field::file()->label('Image')]);
     $field->val([['name' => 'Oscar', 'email' => '*****@*****.**', 'age' => '35', 'image' => ['name' => '1.png', 'type' => 'image/png', 'tmp_name' => '/tmp/phpTobJ71', 'error' => 0, 'size' => 2297]], ['name' => 'Laura', 'email' => '*****@*****.**', 'age' => '35', 'image' => ['name' => '2.png', 'type' => 'image/png', 'tmp_name' => '/tmp/phpTobJ72', 'error' => 0, 'size' => 2297]]]);
     $this->assertCount(2, $field->val());
     $this->assertEquals('Laura', $field[1]['name']->val());
     $duplicate = $field->getTemplateChild();
     $this->assertEquals('::n::[name]', $duplicate['name']->attr('name'));
     $this->assertEquals('2.png', $field[1]['image']->val()['name']);
 }
Beispiel #2
0
 public function testForm()
 {
     $form = new Form();
     $form->action('index.php')->method('post');
     $form->add(['name' => Field::text()->maxlength(50)->required()->label('Your name'), 'email' => Field::email()->label('Your email'), 'telephone' => Field::tel()->label('Telephone number'), 'gender' => Field::choose(['m' => Field::radio()->label('Male'), 'f' => Field::radio()->label('Female')]), 'born' => Field::collection(['day' => Field::number()->min(1)->max(31)->label('Day'), 'month' => Field::number()->min(1)->max(12)->label('Month'), 'year' => Field::number()->min(1900)->max(2013)->label('Year')]), 'language' => Field::select()->options(array('gl' => 'Galician', 'es' => 'Spanish', 'en' => 'English'))->label('Language'), 'friends' => Field::duplicable(['name' => Field::text()->label('Name'), 'email' => Field::email()->label('email'), 'age' => Field::number()->label('Age')]), 'action' => Field::choose(['save' => Field::submit()->html('Save changes'), 'duplicate' => Field::submit()->html('Save as new value')])]);
     $data = array('name' => 'Manuel', 'email' => null, 'telephone' => null, 'gender' => 'm', 'born' => array('day' => 23, 'month' => 12, 'year' => 2013), 'language' => 'gl', 'friends' => array(array('name' => 'Luis', 'email' => '*****@*****.**', 'age' => 30)), 'action' => 'save');
     $form->val($data);
     $this->assertTrue($form->isValid());
     $form->addValidator('myValidator', function ($form) {
         $val = $form['name']->val();
         return empty($val) ? true : 'The name value must be empty';
     });
     $this->assertFalse($form->isValid());
     $this->assertEquals('The name value must be empty', $form->error());
 }