Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaceall is not a function #285

Open
Vadim0004 opened this issue Apr 12, 2019 · 6 comments
Open

replaceall is not a function #285

Vadim0004 opened this issue Apr 12, 2019 · 6 comments

Comments

@Vadim0004
Copy link

При добавлении нового инпута проиисходит ошибка (replaceall is not a function).
jquery.multipleInput.js?v=1554989766:291 Uncaught TypeError: settings.jsTemplates[i].replaceAll is not a function
at addInput (jquery.multipleInput.js?v=1554989766:291)
at HTMLDivElement. (jquery.multipleInput.js?v=1554989766:139)
at HTMLDivElement.dispatch (jquery.js?v=1553677094:5183)
at HTMLDivElement.elemData.handle (jquery.js?v=1553677094:4991)

    for (var i in settings.jsTemplates) {
        jsTemplate = settings.jsTemplates[i]
            .replaceAll('{' + settings.indexPlaceholder + '}', data.currentIndex)
            .replaceAll('%7B' + settings.indexPlaceholder + '%7D', data.currentIndex);

        window.eval(jsTemplate);
    }

ПРи добавлении нового инпута не пересчитует счетчик из за этого. Все новые инпуты с одинаковым параметром name="ModalForm[codes][1]".

field($model, 'codes')->widget(MultipleInput::class, [ 'max' => 50, 'min' => 0, // should be at least 2 rows 'allowEmptyList' => false, 'enableGuessTitle' => true, 'addButtonPosition' => MultipleInput::POS_HEADER, // show add button in the header ])->label(false);?>
@unclead
Copy link
Owner

unclead commented Apr 13, 2019

я думаю проблема была в том, что метод определялся после вызова в коде, перенес в начало файла 2fcdcd6

но у меня в принципе не воспроизводилась эта ошибка

@unclead unclead closed this as completed Apr 13, 2019
@Vadim0004
Copy link
Author

Почему то ошибка не пропала после фикса.

Uncaught TypeError: settings.jsTemplates[i].replaceAll is not a function

@unclead
Copy link
Owner

unclead commented Apr 15, 2019

@Vadim0004 ну тогда нужно больше информации: что за браузер, какая версия виджета, пример кода для воспроизведения

@Vadim0004
Copy link
Author

<script src="/assets/a5bb85d1/yii.js?v=1553677094"></script>

--
  | <script src="/assets/a5bb85d1/yii.validation.js?v=1553677094"></script>
  | <script src="/assets/ea6e3b95/js/jquery.multipleInput.js?v=1555315737"></script>
  | <script src="/assets/a5bb85d1/yii.activeForm.js?v=1553677094"></script>
  | <script src="/assets/de966f74/js/bootstrap.js?v=1553677094"></script>
  | <script src="/metronic/global/plugins/bootstrap-select/js/bootstrap-select.min.js"></script>
  | <script src="/metronic/global/plugins/bootstrap-editable/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
  | <script src="/js/lib/mustache.min.js?v=1543159264"></script>
  | <script src="/js/lib/noty.min.js?v=1543159264"></script>
  | <script src="/js/main.js?v=1554300695"></script>
  | <script src="/metronic/global/plugins/js.cookie.min.js"></script>
  | <script src="/metronic/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js"></script>
  | <script src="/metronic/global/plugins/jquery.blockui.min.js"></script>
  | <script src="/metronic/global/scripts/app.min.js"></script>
  | <script src="/metronic/layouts/layout/scripts/layout.min.js"></script>

Может проблема что jquery.multipleInput.js подключается у меня до activeForm?

@unclead
Copy link
Owner

unclead commented Apr 15, 2019

@Vadim0004 я же попросил написать браузер, версию виджета и ваш пример кода

@unclead unclead reopened this Apr 15, 2019
@Vadim0004
Copy link
Author

Vadim0004 commented Apr 16, 2019

Версия Crome - Version 70.0.3538.110 (Official Build) (64-bit).
Версия виджета Version "unclead/yii2-multiple-input": "~2.0" (2.21.1)

CONTROLLER

/**
     * @return string|yii\web\Response
     */
    public function actionCreate() {

        $form = new LinkApiCreateForm();
        $user = yii::$app->getUser()->identity;

        if($form->load(Yii::$app->request->post()) && $form->validate()) {
            try {
                $response = $this->lk->generateApiMethod(LinkClient::METHOD_NAME)->createCampaign($form, $user);
                Yii::$app->getSession()->setFlash('success', $response);
                sleep(3);

                return $this->redirect(['campaigns/index']);
            } catch(DomainException $e) {
                Yii::$app->errorHandler->logException($e);
                Yii::$app->session->setFlash('error', $e->getMessage());
            }
        }

        return $this->render('create', [
            'model' => $form,
        ]);
    }

FORM

<?php

namespace backend\models\forms\linkShortener;


use yii\base\Model;
use common\services\linkShortener\LinkClient;
use GuzzleHttp\Client;

class LinkApiCreateForm extends Model {

    public $name;
    public $promocodes;

    public function rules(): array {
        return [
            [['name', 'promocodes'], 'required'],
            [['name'], 'validateName'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    public function validateName($attribute): void {
        $class = new LinkClient(new Client());

        $existCompany = $class->generateApiMethod(LinkClient::METHOD_NAME)->getListCampaigns();

        if(array_key_exists($this->$attribute, $existCompany->toArray())) {
            $this->addError($attribute, "This name $this->name is already exist!");
        }
    }
}

VIEW

<?php


use yii\helpers\Html;
use yii\widgets\ActiveForm;
use unclead\multipleinput\MultipleInput;

/**
 * @var $this yii\web\View
 * @var $form yii\widgets\ActiveForm
 * @var $model backend\models\forms\linkShortener\LinkApiCreateForm
 * $errors
 */

?>

<section>
    <div class="container">
        <div class="row">
            <?php $form = ActiveForm::begin(); ?>
                <h4>Create</h4>
                <div class="box-body">
                    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
                    <?= $form->field($model, 'promocodes')->widget(MultipleInput::class, [
                        'max'               => 10,
                        'min'               => 2,
                        'allowEmptyList'    => false,
                        'enableGuessTitle'  => true,
                        'addButtonPosition' => MultipleInput::POS_FOOTER, // show add button in the header
                    ])->label(false);?>
                </div>
        </div>

        <div class="form-group">
            <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
        </div>

        <?php ActiveForm::end(); ?>
    </div>
</section>

При добавлении нового инпута воспроизводится ошибка :

jquery.multipleInput.js?v=1555315737:311 Uncaught TypeError: settings.jsTemplates[i].replaceAll is not a function
    at addInput (jquery.multipleInput.js?v=1555315737:311)
    at HTMLDivElement.<anonymous> (jquery.multipleInput.js?v=1555315737:159)
    at HTMLDivElement.dispatch (jquery.js?v=1553677094:5183)
    at HTMLDivElement.elemData.handle (jquery.js?v=1553677094:4991)

@unclead unclead added this to the 3.0 milestone Jun 26, 2021
@unclead unclead added this to To do in Refactoring Aug 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants