Hello everyone:
First of all I don’t know if posting this here is correct, if not please move it.
Here I go:
I can’t figure out how to load the items in a SortableInput from the database.
How is the right way to do it? Do I have to make a query in the model and pass it to $items in the widget?
I’m trying to use the example #5 in my _form.php SortableInput, load data from tableA in the rigth list, drag&drop to the left list (which starts empty) and save the elements dropped to tableB by id.
Here’s what I’ve got so far, but it loads only one element with a 0 displayed.
<div class="row">
<div class="col-sm-6">
<?= $form->field($model, 'receta_id')->widget(SortableInput::classname(), [
'name' => 'kv-conn-1',
'items' => [],
'hideInput' => false,
'sortableOptions' => [
'itemOptions' => ['class'=>'alert alert-warning'],
'connected' => true,
],
'options' => ['class' => 'form-control', 'readonly' => true]
]);
?>
</div>
<div class="col-sm-6">
<?= $form->field($model, 'dosis_id')->widget(SortableInput::classname(), [
'name' => 'kv-conn-2',
'items' => $items= [ArrayHelper::map(Dosis::find()->all(),'id_dosis','cantidad')],
'hideInput' => false,
'sortableOptions' => [
'connected' => true,
],
'options' => ['class' => 'form-control', 'readonly' => true]
]);
?>
</div>
</div>
I know it looks like a trivial thing, but I’m only 2 weeks working with Yii2 and still don’t have the grasp of all the elements involved.
Thank you.