lara-zeus/matrix-choice

Checked Option

Closed this issue · 8 comments

Hello Dear ,

Thanks for your work ,
i need to know if i have old values and i need to make checked attribute for some input,
how i can make some of radio checked ? .

Regards

hey, I wish if you shard some code and where are you using this
in a resource or a page
by default the "edit" should work and fill the values from your DB

but giving the following example you can set the values using formatStateUsing like this

Matrix::make('question')
      ->asCheckbox()
      ->formatStateUsing(fn()=>[
          'sat'=>['one'=>true],
          'sun'=>['two'=>true],
          'mon'=>['three'=>true],
      ])
      ->columnData([
          'one'=>'One Item',
          'two'=>'Two Item',
          'three'=>'Three Item',
      ])
      ->rowData([
          'sat' => 'Saturday',
          'sun' => 'Sunday',
          'mon' => 'Monday',
      ]),

if you have values without keys:

->formatStateUsing(fn()=>[
        [0=>true],
        [1=>true],
        [2=>true],
    ])
    ->columnData([
        'one',
        'two',
        'three',
    ])
    ->rowData([
        'sat',
        'sun',
        'mon',
    ])

and you can always dd() the form and see how the array is structured

Dear,
Thanks For Your Replay ,
here is my code ,
image

can you feed me back please ,

i will try with your feed back ,
and i will feed you back ,

Thanks Again <3

Dear,
it's working With this way ,

image

image

but how i can get pass my old values with ->currentData([])

like be this

->currentData([ // This Is My Old Choices Or On In Edit Step
'Question One',
'Question Five',
]),

Best Regards

in this case you should try use key values to store the data
the:
'Question One',
'Question Five',

is the labels not the values
and it all depend how you store the data

Thanks Dear,
i will try and feed you back ,
i like your code

Regards

Dear,

Kindly please help me and feed me back ,
is there is any wat to make radio checked from blade file ?
this is your code ,
can you tell me please ?

image

the issue here with ->formatStateUsing()
it's working ,
but i can't control code ,