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

Checked Option #6

Open
Dr-Maspix opened this issue Feb 27, 2024 · 8 comments
Open

Checked Option #6

Dr-Maspix opened this issue Feb 27, 2024 · 8 comments

Comments

@Dr-Maspix
Copy link

Dr-Maspix commented Feb 27, 2024

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

@atmonshi
Copy link
Member

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',
      ]),

@atmonshi
Copy link
Member

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

@Dr-Maspix
Copy link
Author

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

can you feed me back please ,

@Dr-Maspix
Copy link
Author

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

Thanks Again <3

@Dr-Maspix
Copy link
Author

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

@atmonshi
Copy link
Member

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

@Dr-Maspix
Copy link
Author

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

Regards

@Dr-Maspix
Copy link
Author

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 ,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants