CMB2-Snippet-Library icon indicating copy to clipboard operation
CMB2-Snippet-Library copied to clipboard

Auto complete not working in third row

Open iranimij opened this issue 5 years ago • 11 comments
trafficstars

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'),
            )
        ) );

iranimij avatar Apr 05 '20 11:04 iranimij

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.

pgroot91 avatar Apr 05 '20 15:04 pgroot91

even if we have 10 options when we arrive to third row ,autocomplete suggestion is still not working .

On Sun, Apr 5, 2020, 8:10 PM Patrick Groot [email protected] wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/CMB2/CMB2-Snippet-Library/issues/105#issuecomment-609436330, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHP2L2UBEHNDQOCMGPVVVLTRLCQ6ZANCNFSM4MAUMUHQ .

iranimij avatar Apr 05 '20 15:04 iranimij

when I check html code in inspect element , althought the first and second inputs have event and work correctly,the third row(input) does not have any event to show autocomplete suggestion after changing input , .

On Sun, Apr 5, 2020, 8:19 PM Iman Heydari [email protected] wrote:

even if we have 10 options when we arrive to third row ,autocomplete suggestion is still not working .

On Sun, Apr 5, 2020, 8:10 PM Patrick Groot [email protected] wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/CMB2/CMB2-Snippet-Library/issues/105#issuecomment-609436330, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHP2L2UBEHNDQOCMGPVVVLTRLCQ6ZANCNFSM4MAUMUHQ .

iranimij avatar Apr 05 '20 16:04 iranimij

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

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

iranimij avatar Apr 06 '20 04:04 iranimij

@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?

tw2113 avatar Apr 06 '20 14:04 tw2113

There is a similar problem in theme option page , there isnt any diffrence between the type of editors

On Mon, Apr 6, 2020, 6:47 PM Michael Beckwith [email protected] wrote:

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

@iranimij https://github.com/iranimij Are you seeing this with classic editor, gutenberg editor, or both?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CMB2/CMB2-Snippet-Library/issues/105#issuecomment-609822855, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHP2L2RV2V6E2ZY7EPXSI5DRLHP7ZANCNFSM4MAUMUHQ .

iranimij avatar Apr 06 '20 16:04 iranimij

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

Pierronimo avatar Jun 05 '20 03:06 Pierronimo

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

tw2113 avatar Jun 05 '20 13:06 tw2113

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 ?

Pierronimo avatar Jun 05 '20 16:06 Pierronimo

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

pixelwatt avatar Dec 09 '20 04:12 pixelwatt

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

Pierronimo avatar Jan 25 '21 20:01 Pierronimo