From ba6f8b4824790fd43e693c3cc55e4a60e4f50e2a Mon Sep 17 00:00:00 2001 From: Lyziane Date: Thu, 5 Jan 2017 16:02:25 -0500 Subject: [PATCH] Still trying to make it "multiple-files-friendly" If you pass the option 'multiple' to upload many files, the default button label becomes plural. Also, it fixes the displayed value after submit: the name of the file if only one or a count of files if many --- src/View/Helper/BootstrapFormHelper.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/View/Helper/BootstrapFormHelper.php b/src/View/Helper/BootstrapFormHelper.php index d4e4c5d..a1a0fa5 100644 --- a/src/View/Helper/BootstrapFormHelper.php +++ b/src/View/Helper/BootstrapFormHelper.php @@ -395,7 +395,7 @@ public function file($fieldName, array $options = []) { 'id' => $fieldName, 'secure' => true, 'count-label' => __('files selected'), - 'button-label' => __('Choose File') + 'button-label' => (isset($options['multiple']) && $options['multiple']) ? __('Choose Files') : __('Choose File') ]; $fakeInputCustomOptions = $options['_input']; @@ -412,9 +412,19 @@ public function file($fieldName, array $options = []) { 'escape' => false ])); - $fakeInputCustomOptions += [ - 'value' => $options['val']['name'] - ]; + if (!empty($options['val']) && is_array($options['val'])) { + if (isset($options['val']['name']) || count($options['val']) == 1) { + $fakeInputCustomOptions += [ + 'value' => (isset($options['val']['name'])) ? $options['val']['name'] : $options['val'][0]['name'] + ]; + } + else { + $fakeInputCustomOptions += [ + 'value' => count($options['val']) . ' ' . $countLabel + ]; + } + } + $fakeInput = $this->text($fieldName, array_merge($fakeInputCustomOptions, [ 'name' => $fieldName.'-text', 'readonly' => 'readonly',