Open Vadim0004 opened 5 years ago
я думаю проблема была в том, что метод определялся после вызова в коде, перенес в начало файла 2fcdcd6d39a8c282ec29b84e7ba3c70a7e8927e7
но у меня в принципе не воспроизводилась эта ошибка
Почему то ошибка не пропала после фикса.
Uncaught TypeError: settings.jsTemplates[i].replaceAll is not a function
@Vadim0004 ну тогда нужно больше информации: что за браузер, какая версия виджета, пример кода для воспроизведения
-- | | | | | | | | | | | | | |
Может проблема что jquery.multipleInput.js подключается у меня до activeForm?
@Vadim0004 я же попросил написать браузер, версию виджета и ваш пример кода
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)
При добавлении нового инпута проиисходит ошибка (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)
ПРи добавлении нового инпута не пересчитует счетчик из за этого. Все новые инпуты с одинаковым параметром name="ModalForm[codes][1]".
<?= $form->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);?>