Skip to content

Populate multiple checkboxes #616

Description

@codetestmg

I am trying to mark checkbox to be marked based on database values .

public function prepopulateHorizontalForm(Request $request){
        Former::populate([
                 'name'=>'former',
                'checkbox_multiple'=>[
                    'apple',
                    'cherry',
                  'banana'
                ]
        ]);

        return view('former.pre-populate-horizontal');
  }

and in view file

{!! Former::checkboxes('checkbox_multiple[]')
                                ->checkboxes([
                                    'Apple' => ['value'=>'apple',], 
                                    'Banana' => ['value'=>'banana'],
                                    'Cherry' => ['value'=>'cherry'],
                                    'Mango' => ['value'=>'mango']
                                    ])
                                  !!}

But its not marking checkbox as marked based on value. Using laravel 12 with latest version of former package

Note : i gone through few github issues and tried but it didn't work .
Even this issue (#523) works but it need manually call check() method .I am trying to check the checkbox using populate method

I was able to solve using below method using (#302)

  'checkbox_multiple'=>[
                        'apple'=>'apple',
                        'cherry'=> 'cherry',
                        'banana'=> 'banana'
                ],

and in blade

 {!! Former::checkboxes('checkbox_multiple[]')
                                ->checkboxes([
                                      'Apple' => ['value'=>'apple','id'=>'checkbox_multiple_0','name'=>'checkbox_multiple[apple]'],
                                    'Banana' => ['value'=>'banana','id'=>'checkbox_multiple_1','name'=>'checkbox_multiple[banana]'],
                                    'Cherry' => ['value'=>'cherry','id'=>'checkbox_multiple_2','name'=>'checkbox_multiple[cherry]'],
                                    'Mango' => ['value'=>'mango','id'=>'checkbox_multiple_3','name'=>'checkbox_multiple[mango]']
                                    ])
                                  !!}

is there any better sollution for this ,Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions