-
Notifications
You must be signed in to change notification settings - Fork 127
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
Embedded does not work correctly #356
Comments
NoteI 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 modelWorksecho MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
'options' => [
'columns' => [
[
'name' => 'opcao'
]
]
]
]
],
])?> Related problemecho MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
]
],
])?>
When update modelAnother problemecho MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
'options' => [
'columns' => [
[
'name' => 'opcao'
]
]
]
]
],
])?>
Related problemecho MultipleInput::widget([
'model' => $model,
'attribute' => 'campos',
'columns' => [
[
'name' => 'pergunta',
'type' => 'textarea',
],
[
'name' => 'opcoes',
'type' => MultipleInput::className(),
]
],
])?>
|
@RodrigoDornelles Hi, thx for the reproduce case. What version of the widget do you use? |
@unclead see
|
@RodrigoDornelles 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);
}
} |
@unclead I did a hardcoded interim fix, this is sufficient for my specific case, but it could be a problem for other cases.
|
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. |
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 😄 ) |
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. |
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
happen
Formulario[campos][1][opcoes][campos[1][opcoes]][0]
should beFormulario[campos][1][opcoes][0]
formulario-campos-1-opcoes-campos-1-opcoes-0
should beformulario-1-campos-opcoes-0
NOTE
thinking now, I believe it's a conflict with the activeform mayable
The text was updated successfully, but these errors were encountered: