wbraganca / yii2-dynamicform

It is widget to yii2 framework to clone form elements in a nested manner, maintaining accessibility.
Other
436 stars 438 forks source link

Upload widget does not work - Dynamic form Yii2 starter kit #311

Open tpjasar opened 3 years ago

tpjasar commented 3 years ago

iam using the widget (trntv\filekit\widget \ Upload) of yii2-starter-kit, implement the use of the dynamic form (wbraganca\dynamicform\DynamicFormWidget), the problem is that the upload widget works only on the first element, when adding Other items fail to load correctly

_form

<?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>

field($model, 'title')->textInput(['maxlength' => true]) ?> field($model, 'category_id')->dropDownList(\yii\helpers\ArrayHelper::map( $categories, 'id', 'name' ), ['prompt' => '']) ?> field($model, 'amount')->textInput() ?> field($model, 'delivery_charge')->textInput() ?> field($model, 'description')->widget( \yii\imperavi\Widget::class, [ 'plugins' => ['fullscreen', 'fontcolor', 'video'], 'options' => [ 'minHeight' => 200, 'maxHeight' => 200, 'buttonSource' => true, 'convertDivs' => false, 'removeEmptyTags' => true, 'imageUpload' => Yii::$app->urlManager->createUrl(['/file/storage/upload-imperavi']), ], ] ) ?>
field($model, 'attachments')->widget( Upload::class, [ 'url' => ['/file/storage/upload'], 'maxFileSize' => 5000000, // 5 MiB, 'acceptFileTypes' => new JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'), ] ); ?> field($model, 'availability')->widget(SwitchInput::className()); ?> field($model, 'status')->dropDownList(\common\models\Product::statuses()) ?> field($model, 'features')->widget( \yii\imperavi\Widget::class, [ 'plugins' => ['fullscreen', 'fontcolor', 'video'], 'options' => [ 'minHeight' => 200, 'maxHeight' => 200, 'buttonSource' => true, 'convertDivs' => false, 'removeEmptyTags' => true, 'imageUpload' => Yii::$app->urlManager->createUrl(['/file/storage/upload-imperavi']), ], ] ) ?>
'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_] 'widgetBody' => '.container-items', // required: css class selector 'widgetItem' => '.item', // required: css class 'limit' => 10, // the maximum times, an element can be cloned (default 999) 'min' => 1, // 0 or 1 (default 1) 'insertButton' => '.add-item', // css class 'deleteButton' => '.remove-item', // css class 'model' => $modelsIngredient[0], 'formId' => 'dynamic-form', 'formFields' => [ 'title', 'description', 'image', 'featured_base_url', 'featured_path' ], ]); ?>
Product Ingredients
$modelIngredient) : ?>
Ingredients:
isNewRecord) { echo Html::activeHiddenInput($modelIngredient, "[{$index}]id"); } ?>
field($modelIngredient, "[{$index}]title")->textInput(); ?>
field($modelIngredient, "[{$index}]image")->widget( Upload::class, [ 'url' => ['/file/storage/upload'], 'maxFileSize' => 5000000, // 5 MiB, 'acceptFileTypes' => new JsExpression('/(\.|\/)(gif|jpe?g|png)$/i'), ] ); ?>
field($modelIngredient, "[{$index}]description")->textarea(); ?>
                    </div>

                 <div class="form-group">

                  <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update',    ['class'=>'btnbtnprimary'])      ?>

                </div>

              <?php ActiveForm::end(); 

               $js = '
               jQuery(".dynamicform_wrapper").on("afterInsert", function(e, item) {

               jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {

               jQuery(this).html("Ingredients: " + (index + 1))
               });
               });

              jQuery(".dynamicform_wrapper").on("afterDelete", function(e) {
              jQuery(".dynamicform_wrapper .panel-title-address").each(function(index) {
              jQuery(this).html("Ingredients: " + (index + 1))
               });
              });
             ';

             $this->registerJs($js);
              ?>

Screenshot_2020-12-05 Create Product

only first one is working the second one not working the value get null in controller.also second one css and js also not working.

mcaralo commented 3 years ago

@wbraganca , boa tarde! Iria justamente usar componente, mas vi esta mensagem. E também tentei pegar o exemplo no seu site, mas está fora do ar. Quando puder, dê uma força nesses pontos! Obrigado e parabéns pelo componente.

desaikalpesh34 commented 2 years ago

I have same issue with widget (trntv\filekit\widget \ Upload) is there any progress with this issue?