-
Notifications
You must be signed in to change notification settings - Fork 77
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
Doesn't work with multiple select. Array to string conversion exception #31
Comments
@tabacitu - this is probably a request for enhancement but the wording is too vague and terse (and there's been no PR nor update to the issue) - I'm closing this - but please reopen if needed. |
I just ran into this issue and I wouldn't say it's a request for enhancement, I see it as bug. Use case: I want to make a selector for days in week (Monday, Tuesday, Wednesday, ..., Sunday) - "Select days on which you want to send notifications". I decided to use Issues:
returns an error:
When specifying the
the select is shown OK, but it doesn't preserve the keys and won't save correctly anyway (the conversion exception)
Is there a way to do this, which I didn't see/try (possible), or is it really a bug? |
The only way one could find out is to read the source, I guess:
In English, are you trying to do something like:
|
Yes, your description is correct. I would just add, that having the keys stored (as provided in array) would be ideal, but I can manage without them (storing just the implicit keys, e.g. I indeed took a look at the code and I think the problem is that the Settings package just doesn't work well with arrays. Normally, you'd specify the field's The only solution I see here is to store the But right now, I'm not sure whether it's possible to make it backwards compatible (my gut is telling me "yes"), so all suggestions are welcome. |
@terion-name , @pavoltanuska , @lloy0076 I just merged an update #69 that should solve the issue. When interpreting the field from the DB to the CRUD, we were casting it to array. Now we're Let me know if it doesn't. |
Unfortunately, it doesn't solve this issue. Example 1 Let's say, I have a settings field with
It doesn't work, because the
and it dies with Ok, that doesn't work. Let's try it without preserving the keys (making the options array one level deep). Example 2
Alright, it looks like it works, array is one level deep:
But!
Weird, shall we look at the
Why is this still a string? Because normally, we'd specify the field's casting on the model, which isn't something we can do on Settings model (without breaking the compatibility for other fields). And that means two things:
So actually, this issue has two sub-issues:
I have outlined the possible solution in #31 (comment), but there is no "5-minute" solution, as it could break the compatibility with other fields. So @tabacitu, please reopen this issue. I'll try to come up with some backwards compatible solution, you are all welcome to help :) |
Wow - thank you for the comprehensive explanation @pavoltanuska . Of course, reopened. |
|
Hi guys, Following up on this. Tested and re-tested this. My conclusions:
{
"name": "value",
"label": "Days",
"type": "select2_from_array",
"options": {
"Monday": "Monday",
"Tuesday": "Tuesday",
"Wednesday": "Wednesday"
},
"allows_null": false,
"default": [],
"allows_multiple": true
} Right now I don't see a solution, other than having another field type, that actually stores a JSON in a hidden input... Will be back... |
I came up with solution that is adding : |
Hi ahmed402, I have the same problem : Array to string conversion (SQL: insert into with a select2_multiple. But I added your code to vendor/backpack/crud/src/app/Http/Controllers/Operations/CreateOperation.php and it don't work :/ |
How to do this setting then. I have created a seeder to on/off setting.
On list it is working fine as expected But when I tried to edit it. It throws me an error Undefined index: name |
I am having this issue in Backpack 5 as well, was this ever resolved? |
Subject
The text was updated successfully, but these errors were encountered: