question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with select2_from_ajax_multiple

See original GitHub issue

I have a field with a select2_multiple that is working well (but i have a lot a data so it’s pretty slow). I want to replace it with the new select2_from_ajax_multiple.

My select2_multiple:

$this->crud->addField([
            'label' => "Relance à faire",
            'type' => 'select2_multiple',
            'name' => 'relances',
            'entity' => 'relances',
            'attribute' => 'full_name',
            'model' => "App\Models\Personne",
            'pivot' => true
        ],'update');

My select2_from_ajax_multiple:

$this->crud->addField([
            'label' => "Relance à faire",
            'type' => "select2_from_ajax_multiple",
            'name' => 'idPersonnes',
            'entity' => 'relances', 
            'attribute' => "full_name", 
            'model' => "App\Models\Personne", 
            'data_source' => url("admin/relanceajax"),
            'placeholder' => "Selectionner une personne",
            'minimum_input_length' => 2,
            'pivot' => true
        ],'update');

It works as i can type in the fields, i have results and i can select many items. But when i save i have this error: BadMethodCallException in Builder.php line 2508: Call to undefined method Illuminate\Database\Query\Builder::idPersonnes()

I’ve try with

'name' => 'relances',
'entity' => 'relances', 

But then i have this error: ErrorException in InteractsWithPivotTable.php line 132: Argument 1 passed to Illuminate\Database\Eloquent\Relations\BelongsToMany::formatRecordsList() must be of the type array, string given, called in /home/ubuntu/workspace/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php on line 96 and defined

Also i when open an edit view for a record that already have some data in the pivot table nothing is displayed.

If somebody can give me a clue… Thanks you.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
webactioncommented, Feb 28, 2017

I am also having a problem just like the one mentioned in this issue.

I have managed to make changes that have resolved most of the bugs with the implementation of the select2_from_ajax_multiple field type.

Before I submit a patch, I would like to know if anyone else has been able to implement with-out changes?

0reactions
Jitendernagarcommented, Jul 14, 2017

I have updated latest version, its working fine on save. But edit case this is not working. so please change on select2_from_ajax_multiple.blade.php. <select name=“{{ $field[‘name’] }}[]” style=“width: 100%” id=“select2_ajax_multiple_{{ $field[‘name’] }}” @include(‘crud::inc.field_attributes’, [‘default_class’ => ‘form-control’]) multiple>

    @if ($old_value)
        @foreach ($old_value as $result_key)
            @php
                $item = $connected_entity->find($result_key);
            @endphp
            @if ($item)
            <option value="{{ $item->getKey() }}" selected>
                {{ $item->{$field['attribute']} }}
            </option>
            @endif
        @endforeach
    @endif
</select>

to

<select name=“{{ $field[‘name’] }}[]” style=“width: 100%” id=“select2_ajax_multiple_{{ $field[‘name’] }}” @include(‘crud::inc.field_attributes’, [‘default_class’ => ‘form-control’]) multiple>

    @if ($old_value)
        @foreach ($old_value as $result_key)
            <option value="{{ $result_key->id }}" selected>
                {{ $result_key->name }}
            </option>
        @endforeach
    @endif
</select>

Thanks, Jitender Gurjar.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select2 AJAX Multiple not working properly - Stack Overflow
Save this question. Show activity on this post. So i have a select2 ajax selector that works perfectly when not using multiple ,...
Read more >
Common problems - The jQuery replacement for select boxes
Select2 does not function properly when I use it inside a Bootstrap modal. ... This issue occurs because Bootstrap modals tend to steal...
Read more >
multiple select in AJAX mode? · Issue #33 · select2 ... - GitHub
hi, i have a multiple select dropdown that i want to populate using ajax. your examples however only indicates just a single selects...
Read more >
Select2 3.5.3
The select below is declared with the multiple attribute. ... Select2 uses jQuery's $.ajax function to execute the remote call by default.
Read more >
Select2 with MultiSelect Box Displaying Problems
I just took another look at it. I think it is slow because you have 6,219 schools in the list. To speed it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found