When I open update "page" I have dynamically rows that are saved in the DB . But how I can manage to delete the rows in actionUpdate to delete them in the DB.The deleted "items" are in array deletedIds
public function actionUpdate($id) {
$model = Component::find()->where(['id' => $id])->one();
$depModels = Dependency::find()->where(['component_id' => $id])->all();
$tractorModels = ArrayHelper::map(Tractormodel::find()->all(), 'id', 'model');
$components = Component::find()->all();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$dependendComponents = Yii::$app->request->bodyParams['ids'];
foreach ($dependendComponents as $dComp) {
$dependencyModel = new Dependency();
$dependencyModel->setAttributes([
'count' => $dComp['quantity'],
'component_id' => $model->id,
'dependent_id' => $dComp['id']
]);
$dependencyModel->save();
}
return $this->redirect(['index', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model, 'tractorModels' => $tractorModels,
'components' => $components, 'depModels' => $depModels,
]);
}
}
and here is my remove row jQUery in "_form"
wrapper.on("click", ".remove_field", function (e) {
var wantedDiv = $(this).parent('div').children().first();
var selectTag = $(wantedDiv).find('select');
var clickedId = $(selectTag).find('[selected=""]').attr('value');
var deletedIdsArray = $('#deletedIDs');
console.log($('#deletedIDs'));
if (clickedId) {
$('#deletedIds').append('<input type="hidden" name="deletedIds[]" value="' + clickedId + '">');
}
e.preventDefault();
$(this).parent('div').remove();
x--;
});