Comments (10)
Note
I did some tests, and realized that the "name" attribute is set correctly when used in columns, but only in a new model, when you go to edit another problem happens.
When create a new model
Works
echo MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
'options' => [
'columns' => [
[
'name' => 'opcao'
]
]
]
]
],
])?>
Related problem
echo MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
]
],
])?>
- name occurred
Formulario[campos][1][opcoes][campos[1][opcoes]][0]
should beFormulario[campos][1][opcoes][0]
- id occurred
formulario-campos-1-opcoes-campos-1-opcoes-0
should beformulario-1-campos-opcoes-0
When update model
Another problem
echo MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
'options' => [
'columns' => [
[
'name' => 'opcao'
]
]
]
]
],
])?>
- name occurred
Formulario[campos][0][opcoes][opcao][opcao]
should beFormulario[campos][0][opcoes][0][item]
- id occurred
formulario-campos-0-opcoes-item-item
should beformulario-campos-0-opcoes-0-item
Related problem
echo MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
]
],
])?>
- name occurred
Formulario[campos][1][opcoes][campos[1][opcoes]][0]
should beFormulario[campos][1][opcoes][0]
- id occurred
formulario-campos-1-opcoes-campos-1-opcoes-0
should beformulario-1-campos-opcoes-0
from yii2-multiple-input.
@RodrigoDornelles Hi, thx for the reproduce case. What version of the widget do you use?
from yii2-multiple-input.
Hi, thx for the reproduce case. What version of the widget do you use?
@unclead see
packge | version |
---|---|
Yii2 | 2.0.42.1 |
Jquery | 3.5.1 |
Plugin | 2.24.0 |
from yii2-multiple-input.
@RodrigoDornelles I can't reproduce it without seeing the code of the model.
from yii2-multiple-input.
I can't reproduce it without seeing the code of the model.
@unclead here
<?php
namespace common\models;
use Yii;
use yii\helpers\Json;
class Formulario extends BaseModel
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'formulario';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
//...
[['campos'], 'safe'],
[['email_copias'], 'each', 'rule' => ['email']],
];
}
/**
* {@inheritdoc}
*/
public function beforeSave($insert)
{
if (!parent::beforeSave($insert)) {
return false;
}
$this->email_copias = Json::encode($this->email_copias);
$this->campos = Json::encode($this->campos);
return true;
}
/**
* {@inheritdoc}
*/
public function afterFind()
{
parent::afterFind();
$this->email_copias = Json::decode($this->email_copias, true);
$this->campos = Json::decode($this->campos, true);
}
}
from yii2-multiple-input.
@unclead I did a hardcoded interim fix, this is sufficient for my specific case, but it could be a problem for other cases.
'value' => fn ($data) => isset($data['opcoes'])? $data['opcoes']['item']: null,
from yii2-multiple-input.
TBH I didn't manage to reproduce the issue so I can't say why it happens. Did you try to debug it? I mean go to the widget's code and try to figure out the root cause?
from yii2-multiple-input.
TBH I didn't manage to reproduce the issue so I can't say why it happens. Did you try to debug it? I mean go to the widget's code and try to figure out the root cause?
I tried debugging and solving, but i found the plugin much more complex than thought.
I'll still work hard on a system, notice anything, or if I can find the problem.
from yii2-multiple-input.
but i found the plugin much more complex than thought.
That's true. The result of years of incremental improvements. I'm working on refactoring it's architecture right now and it's quite complicated as well (even considering I did most of the features 😄 )
from yii2-multiple-input.
The Field even works visually, but it puts "name" attributes in the html meaningless which leads to an incorrect request not being able to save correctly.
expected
<input type="text" id="formulario-1-campos-opcoes-0" class="form-control is-valid" name="Formulario[campos][1][opcoes][0]" aria-invalid="false">
happen
<input type="text" id="formulario-campos-1-opcoes-campos-1-opcoes-0" class="form-control is-valid" name="Formulario[campos][1][opcoes][campos[1][opcoes]][0]" aria-invalid="false">
* **name** occurred `Formulario[campos][1][opcoes][campos[1][opcoes]][0]` should be `Formulario[campos][1][opcoes][0]` * **id** occurred `formulario-campos-1-opcoes-campos-1-opcoes-0` should be `formulario-1-campos-opcoes-0`
NOTE
thinking now, I believe it's a conflict with the activeform mayable
in my case i've had trying workaround to make custom generate element DOM id/name attribute in afterInit and afterAddRow JS event with specific array value element.
from yii2-multiple-input.
Related Issues (20)
- Add manual for each field for custom tabular input? HOT 4
- duplicate keys causing strange behavior HOT 2
- Adding new row with DepDrop suddenly not working.
- Is it possible to keep the selected value of a DepDrop when submit returns error? HOT 1
- wrong version hardcoded in composer.json HOT 1
- add button position POS_ROW_BEGIN is shown under the first column HOT 6
- render addons in text fields HOT 2
- Html name attribute HOT 2
- all icon missing HOT 7
- Не работает подсветка ошибок при валидации вновь добавленных полей HOT 1
- The array is converted into an object
- Add button not showing in actionUpdate HOT 1
- Can't handle model update HOT 2
- Yii2 advanced template and Bootstrap 5 HOT 1
- Unable to get the file. HOT 1
- Иногда не обновляется currentIndex после добавления первой строки HOT 3
- Не работает подсветка ошибок если полей более 9 HOT 1
- DateTimePicker HOT 1
- Error showing problem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-multiple-input.