I'm creating a form view at hand, and I'm following this tutorial (here) .
Apparently my form is working, the problem is being in fields that have dependencies. The "unit" field depends on the "Company" field, when I change the "company" field, the following message appears: "A widget with class name 'form' has not been bound to the controller".
To understand better, I am putting my "fields.yaml" file and my code below.
fields:
company:
label: Empresa
emptyOption: '---'
span: auto
type: dropdown
unit:
label: Unidade
span: auto
dependsOn:
- company
type: dropdown
public function onShowCreateOpportunity()
{
$model = new \CRM\Events\Models\Opportunity;
$config = $this->makeConfig('$/crm/events/models/opportunity/fields.yaml');
$config->arrayName = 'Opportunity';
$config->model = $model;
$widget = $this->makeWidget('Backend\Widgets\Form', $config);
$widget->form = $model;
$widget->bindToController();
$this->vars['model'] = $model;
$this->vars['widget'] = $widget; //its for test
return $this->makePartial('views/sales/sales_new', [
'widget' => $widget, //its for test
]);
}
<div id="popupSales">
<div class="modal-header">
<button type="button" class="close" data-dismiss="popup">×</button>
<h3 class="modal-title" align="center">Nova Oportunidade</h3>
</div>
<?= Form::open() ?>
<div class="modal-body">
<div class="row">
<div class="col-sm-12" style="margin-top: 20px;">
<?= $widget->render() ?>
</div>
</div>
</div>
<div class="modal-footer" style="margin-top: 5px;">
<div class="loading-indicator-container">
<button data-request="onCreateNew" class="btn btn-primary">
Cadastrar
</button>
<button
type="button"
class="btn btn-primary"
data-dismiss="popup">
Fechar
</button>
</div>
</div>
<?= Form::close() ?>
</div>
As I mentioned above, the form is displaying, it is showing the correct values in the "COMPANY" field, however, when I select any "Company" the "UNIT" field does not load and shows the message I quoted above.