Open
Description
Hello @kristijanhusak ,
I am facing an issue with some checkboxes.
Details
Inside a form I am loading a collection type=>'form'
and inside this collectionForm, I am loading another dynamic childForm in order to bind a json field of the child model
//collection type=>'form'
public function buildForm()
{
$this->add($name, 'collection', [
'type' => 'form',
'data' => $values, //Collection,
'class' => 'DynamicProjectFieldForm',
]);
}
//inside DynamicProjectFieldForm
public function buildForm()
{
$this->add('field_type_id', 'hidden', ['value' => $projectFieldType->id]);
//childForm
$this->add('fields', 'form', [ 'class' => $this->getModelJsonFields()]);
}
private function getModelJsonFields()
{
$subForm = $this->formBuilder->plain();
foreach ($jsonFields as $field) {
$opts = [
'label' => $field['label'],
'rules' => $field['required'] ? 'required' : '',
'client_validation' => true,
'default_value' => $field['default_value'],
];
$subForm->add($field['name'], $field['type'], $opts);
}
return $subForm;
}
The Issue
The result is Awesome All my childModel fields are created and binded like a charm. Except one major glitch. All The Checkboxes have wrong id and the labels can't trigger the inputs to change
As you can see on the following code snippet, the id didn't inherit the depth of the field like the name attribute
<div class=" custom-control custom-checkbox ">
<input class="custom-control-input" id="chkBoxName" checked="checked" name="fieldValues[domain][1][fields][chkBoxName]" type="checkbox" value="1">
<label for="fieldValues[domain][1][fields][chkBoxName]" class="custom-control-label small">Label-Name</label>
</div>
Also as I found on CheckableType, the id is given on its initialization but I wasn't able to find where the field is processed, as it gains depth