-
Notifications
You must be signed in to change notification settings - Fork 258
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
Multiselect not showing selected options in edit form in Laravel 5.1 #206
Comments
This is a veeeeery old problem with javascript chosen library... take a look at harvesthq/chosen#92 and you will found many solutions to prevent this behavior. |
I encountered the same problem. |
For me, this is a BUG on chosen... buuuut... there is a solution. Just set the width of .chosen-container on you css. maybe with !important clausule. Regards... |
I found the reason, this is caused by the changes of lists method in Laravel 5.1, as stated at http://laravel.com/docs/5.1/upgrade#upgrade-5.1.0
So I think the solution is to use Custom Form Elements. |
It seems I have similar problem. Laravel 5.1 and the latest sleeping-owl 2 version. Currently sleeping-owl 2.x uses bootstrap-multiselect component, but not choosen as mentioned above. I managed the getList() function as required in laravel 5.1
When I try to edit form with multiselect field, currently selected options are not active (I see "Nothing selected" text instead of it, also checkboxes from dropdown are not selected). But form contains list of options, and I can create entity with multiselect field, edit it, etc. Any prediction why edit form is not filled by previously set values for multiselect field? Thank you in advance. |
@turistua At line 121, if you change $result = $result->lists($part); to $result = $result->lists($part)->all(); then your multiselect field should be working properly. This solution is quick but not in a proper way. For me, I choose to use Custom Form Elements.
<?php
namespace App\Forms;
use SleepingOwl\Admin\Exceptions\ValueNotSetException;
use Illuminate\Database\Eloquent\Relations\Relation;
use SleepingOwl\Admin\Models\Form\FormItem\MultiSelect;
class MultiSelect2 extends MultiSelect
{
protected $name;
protected $label;
function __construct()
{
parent::__construct($this->name, $this->label);
}
/**
* @throws ValueNotSetException
* @return mixed
*/
public function values()
{
$result = $this->form->instance;
if (is_null($this->value)) {
throw new ValueNotSetException;
}
$parts = explode('.', $this->value);
foreach ($parts as $part) {
if ($result instanceof Relation) {
$result = $result->lists($part)->all();
} else {
$result = $result->$part();
}
}
if (count($result) == 0 && ! $this->form->instance->exists) {
return $this->getDefault();
}
return $result;
}
public function setName($name)
{
$this->name = $name . '[]';
return $this;
}
public function setLabel($label)
{
$this->label = $label;
return $this;
}
}
FormItem::register('multiSelect2', \App\Forms\MultiSelect2::class);
FormItem::multiSelect2('clusters')
->setName('clusters')
->setLabel('Business Clusters')
->list(\App\Cluster::class)
->value('clusters.cluster_id')
; |
@tylerteh mentioned a good way to solve this problem, but I think it must be updated a little The main problem (for me) is: So, your
|
This fixes "Integrity constraint violation: 1052 Column 'id' in field list is ambiguous" for Laravel 5.1+
I'm having issues with my multi-select .It works fine but after sometime it submits empty string and it bypasses all the validation |
Hello, in my application I use form with multiselect. I followed instruction in this issue: #97. I only changed things that were required by Laravel 5.1 (e.g \App\File::class instead of 'File'). Saving works perfectly fine however edit doesn't show already selected items. Below is my code:
I need to do something like: each 'ArchitectEntry' can have multiple files attached and file can be attached to multiple 'ArchitectEntries'
Related Model:
Base model
Admin model
Does anyone know solution to this problem?
Thanks.
The text was updated successfully, but these errors were encountered: