Skip to content

Auto complete not working in third row #105

Open

Description

@iranimij

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

Activity

  1. pgroot91 commented on Apr 5, 2020

    @pgroot91

    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.

  2. iranimij commented on Apr 5, 2020

    @iranimij
    Author
  3. iranimij commented on Apr 5, 2020

    @iranimij
    Author
  4. iranimij commented on Apr 6, 2020

    @iranimij
    Author

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

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

  5. tw2113 commented on Apr 6, 2020

    @tw2113
    Contributor

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

  6. iranimij commented on Apr 6, 2020

    @iranimij
    Author
  7. Pierronimo commented on Jun 5, 2020

    @Pierronimo

    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

  8. tw2113 commented on Jun 5, 2020

    @tw2113
    Contributor

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

  9. Pierronimo commented on Jun 5, 2020

    @Pierronimo

    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 ?

  10. pixelwatt commented on Dec 9, 2020

    @pixelwatt

    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

  11. Pierronimo commented on Jan 25, 2021

    @Pierronimo

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions