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

Auto complete not working in third row #105

Open
iranimij opened this issue Apr 5, 2020 · 11 comments
Open

Auto complete not working in third row #105

iranimij opened this issue Apr 5, 2020 · 11 comments

Comments

@iranimij
Copy link

iranimij commented Apr 5, 2020

I set up an autocomplete field type using the following example:
https://github.com/WebDevStudios/CMB2-Snippet-Library/blob/master/custom-field-types/autocomplete-field-type.php

Screenshot_2020-04-05 Add a New Post ‹ Old Realtybloc — WordPress

First when I click on the first row autocomplete is working successfully but at third row autocomplete is not working.

wordpress version : 5.4

my code :

$cmb = new_cmb2_box( array(
            'id' => 'autocomplete_test',
            'title' => __('Autocomplete Field Examples', 'autocomplete_cmb2'),
            'object_types' => array('post'),
        ) );

`

$cmb->add_field( array(
            'name' => __('Related Fruits', 'autocomplete_cmb2'),
            'desc' => __('Repeatable related fruits', 'autocomplete_cmb2'),
            'id' => $prefix.'related_fruits',
            'type' => 'autocomplete',
            'repeatable' => true,
            'repeatable_class' => 'related-fruits',
            'options' => array(
                array('value' => 1, 'name' => 'Apple'),
                array('value' => 2, 'name' => 'Orange'),
                array('value' => 3, 'name' => 'Grape'),
                array('value' => 4, 'name' => 'Grape1'),
                array('value' => 5, 'name' => 'Grape2'),
                array('value' => 6, 'name' => 'Grape3'),
                array('value' => 7, 'name' => 'Grape4'),
            )
        ) );
@pgroot91
Copy link

pgroot91 commented Apr 5, 2020

The only thing i can come up with is that apple is already selected from the list...

Never used this field before but i was looking for exactly this.

@iranimij
Copy link
Author

iranimij commented Apr 5, 2020 via email

@iranimij
Copy link
Author

iranimij commented Apr 5, 2020 via email

@iranimij
Copy link
Author

iranimij commented Apr 6, 2020

78523637-ad2fdd00-77e6-11ea-9c83-40093784349f

in this picture you see the third row does not have any events.

@tw2113
Copy link
Contributor

tw2113 commented Apr 6, 2020

@johnsonpaul1014 I think this is your autocomplete plugin originally. Do you have any thoughts or insights on what's going on?

@iranimij Are you seeing this with classic editor, gutenberg editor, or both?

@iranimij
Copy link
Author

iranimij commented Apr 6, 2020 via email

@Pierronimo
Copy link

Pierronimo commented Jun 5, 2020

Hi @tw2113 , hi @iranimij ,
I have the same problem, any clue to solve this ?
I saw the same thing than @iranimij, after the second row, the event is not present.

Also, the two first rows doesn't have "id" neither "name whereas the third one and more have an id and a name but null.

Capture d’écran 2020-06-04 à 22 43 19

@tw2113
Copy link
Contributor

tw2113 commented Jun 5, 2020

I don't have any new insights on this one, sorry.

@Pierronimo
Copy link

Ok, thanks for answering.

I keep searching and I could see that there is no problem when the field is not repeatable and inside a repeatable group.
Maybe thanks to the ajax loading of the repeatable group ?

The repeatable field doesn't have ajax reloading, and so the javascript event is not attached to the added field.
The second row have the event because it is already present on document.ready (hidden but present). but the third row and more are added with javascript without reloading and the event is not attached.

I can see what is the problem but I don't have the necesary knowledge in javascript to solve it.

Maybe with @iranimij or @johnsonpaul1014 we can solve it ?

@pixelwatt
Copy link

pixelwatt commented Dec 9, 2020

I was able to get it working by modifying the script portion of the autocomplete_cmb2_render_autocomplete() function. Basically, all of the js code after jQuery(document).ready(function($) { is moved into a function that gets fired on document.ready, and then refired when the Add Row button for the field gets clicked. I've attached my modified version of the file.
autocomplete-field-type.php.zip

@Pierronimo
Copy link

Hi @pixelwatt.
I just tried it and it works good for me too, nice job !
Thanks a lot !

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

5 participants