kristijanhusak / laravel-form-builder

Laravel Form builder for version 5+!
https://packagist.org/packages/kris/laravel-form-builder
MIT License
1.71k stars 296 forks source link

Radio button has problem #712

Open sdvpnin opened 1 year ago

sdvpnin commented 1 year ago
        ->add('active', 'choice', [
            'label' => __('cruds.object.fields.active'),
            'choices' => ['yes' => 'Yes', 'no' => 'No'],
            'choice_options' => [
                'label_attr' => ['class' => 'label-class mx-1'],
            ],
            'selected' => 'no',
            'label_attr' => ['class' => 'col-md-2'],
            'expanded' => true,
            'multiple' => false
        ])

In model has yes value but it's selected no. Add time work perfect with selected but edit time it's create the problem.so it's taking from selected attributes but not from the model i try both direct 'no' and with array also ['no']

rudiedirkx commented 1 year ago

Can you put some debug in ChoiceType::buildCheckableChildren()? And maybe in CheckableType? To find out where the bug comes from. I never use choice fields, but rdx/laravel-form-builder-extras, so you're going to have to help me.

ukeloop commented 10 months ago

Model data is used only if the value property (value or selected) is NULL. You can use default_value.

$this
    ->add('active', 'choice', [
        'choices' => ['yes' => 'Yes', 'no' => 'No'],
        'default_value' => 'no',
    ]);