Skip to content

Commit fa8b26b

Browse files
committed
Container: added addMultiUpload()
1 parent 240c4a4 commit fa8b26b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Forms/Container.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ public function addUpload($name, $label = NULL, $multiple = FALSE)
293293
}
294294

295295

296+
/**
297+
* Adds control that allows the user to upload multiple files.
298+
* @param string control name
299+
* @param string label
300+
* @return Nette\Forms\Controls\UploadControl
301+
*/
302+
public function addMultiUpload($name, $label = NULL)
303+
{
304+
return $this[$name] = new Controls\UploadControl($label, TRUE);
305+
}
306+
307+
296308
/**
297309
* Adds hidden form control used to store a non-displayed value.
298310
* @param string control name

tests/Forms/Controls.UploadControl.loadData.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test(function() { // container
8989

9090
test(function() { // multiple (in container)
9191
$form = new Form;
92-
$input = $form->addContainer('multiple')->addUpload('avatar', NULL, TRUE);
92+
$input = $form->addContainer('multiple')->addMultiUpload('avatar');
9393

9494
Assert::true( $form->isValid() );
9595
Assert::equal( array(new FileUpload(array(
@@ -111,7 +111,7 @@ test(function() { // multiple (in container)
111111

112112
test(function() { // missing data
113113
$form = new Form;
114-
$input = $form->addUpload('empty', NULL, TRUE)
114+
$input = $form->addMultiUpload('empty')
115115
->setRequired();
116116

117117
Assert::false( $form->isValid() );
@@ -147,7 +147,7 @@ test(function() { // malformed data
147147
Assert::false( $input->isFilled() );
148148

149149
$form = new Form;
150-
$input = $form->addUpload('avatar', NULL, TRUE);
150+
$input = $form->addMultiUpload('avatar');
151151

152152
Assert::true( $form->isValid() );
153153
Assert::equal( array(), $input->getValue() );
@@ -183,7 +183,7 @@ test(function() { // validators
183183

184184
test(function() { // validators on multiple files
185185
$form = new Form;
186-
$input = $form->addContainer('multiple')->addUpload('avatar', NULL, TRUE)
186+
$input = $form->addContainer('multiple')->addMultiUpload('avatar')
187187
->addRule($form::MAX_FILE_SIZE, NULL, 3000);
188188

189189
Assert::false( Validator::validateFileSize($input, 150) );

0 commit comments

Comments
 (0)