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

How to save multiple select checkbox in single field? #238

Closed
vrdvishwas opened this issue Apr 10, 2019 · 3 comments
Closed

How to save multiple select checkbox in single field? #238

vrdvishwas opened this issue Apr 10, 2019 · 3 comments
Labels
type: documentation This issue means we need to improve docs

Comments

@vrdvishwas
Copy link

`@extends('twill::layouts.form')

@section('contentFields')
@formfield('checkboxes', [
'name' => 'attributes',
'label' => 'Attributes',
'inline' => false,
'options' => [
[
'value' => 'text',
'label' => 'Text'
],
[
'value' => 'textarea',
'label' => 'Textarea'
],
[
'value' => 'editor',
'label' => 'WYSIWYG Editor'
],
[
'value' => 'image',
'label' => 'Image'
],
[
'value' => 'file',
'label' => 'File Upload'
],
]
])
@Stop
`

I can't able to save multiple select in table field. How i can save this.

@vrdvishwas
Copy link
Author

Does this problem has no solutions?

@ifox
Copy link
Member

ifox commented Apr 18, 2019

Hi @vrdvishwas,

Take a look at https://spectrum.chat/twill/general/db-type-for-multi-select-fields~956d322d-07ba-4a76-a6ab-5a2b7e57da8e.

Depending on how you want to structure data you really have many choices here: one boolean column per value, one json column storing selected values, a belongsToMany relationship, etc.

In the repository section of the documentation you'll find that Twill gives you hooks to prepare data before saving (prepareFieldsBeforeSave), save more data after the model itself has been saved (afterSave) and to format data out of the database to feed your form fields if the data structure doesn't match 1 to 1 (getFormFields).

If you find yourself having to repeat code across multiple models, you can use the same approach Twill takes to share features through PHP traits. It is inspired by Laravel trait booting where the name of the hook in the trait contains the name of the trait itself. For example in Twill, the HandleMedias trait defines a afterSaveHandleMedias method that is called by the afterSave method of the repository including that trait.

@ifox ifox added type: documentation This issue means we need to improve docs question labels Apr 21, 2019
@yanhao-li
Copy link

Confirmed checkboxes has been supported in the PR: #410
Closing this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation This issue means we need to improve docs
Projects
None yet
Development

No branches or pull requests

3 participants