Skip to content
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

CheckableType (checkbox) wrong id (html-attribute ) #460

Open
manolismax opened this issue Nov 2, 2018 · 2 comments
Open

CheckableType (checkbox) wrong id (html-attribute ) #460

manolismax opened this issue Nov 2, 2018 · 2 comments
Labels

Comments

@manolismax
Copy link

manolismax commented Nov 2, 2018

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

@rom1vtle
Copy link

rom1vtle commented Mar 4, 2019

I am facing the same issue. Thanks

@rudiedirkx
Copy link
Collaborator

Relevant: #434

There are several scenarios where plain forms behave wrongly. A named form (a separate class) might work. Try that.

@rudiedirkx rudiedirkx added the bug label Feb 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants