LeaVerou / awesomplete

Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
http://leaverou.github.io/awesomplete/
MIT License
6.97k stars 611 forks source link

Square brackets in first and last item of Thymeleaf lists #17182

Closed AndRossi closed 5 years ago

AndRossi commented 5 years ago

I'm developing a web application using Java, Spring Boot and Thymeleaf. I am experiencing an issue with an awesomplete input object. I set the data-list attribute of the awesomplete input as a Thymeleaf list of String objects (so I use attribute th:data-list):

        <div class="form-group row">
            <label for="id" class="col-form-label">Istituzione</label>
            <div>
                <input id="id" class="select form-control awesomplete"
                       required=""
                       placeholder="Istituzione"
                       th:field="${roleForm.institutionName}"
                       th:data-list="${institutions}">
            </div>
        </div>

This is the result:

Schermata 2019-03-29 alle 22 50 58

As you can see, it kinda works, except for two weird square brackets. The affected items are "Ambasciata italiana a Parigi" and "Ambasciata Statunitense a Roma". Those brackets are not part of the original strings sent by the backend (that's the first thing I have checked).

I believe that those brackets are just the result an error while parsing the the Thymeleaf String List. As a matter of fact, "Ambasciata italiana a Parigi" is the first item in the String List sent by the backend, and "Ambasciata Statunitense a Roma" is the last one.

I'm not really sure of how the Thymeleaf String List is encoded, but it may attach an additional "[" before the first item, and an an additional "]" after the last one. In this case, it just makes sense that the parsing system concatenates them to the first and last items respectively.

LeaVerou commented 5 years ago

This looks like a problem that is very specific to your setup, and not an Awesomplete bug. We cannot add code to Awesomplete that's specific to Java (or any other specific setup), you may need to inspect what's being passed there and possibly stringify it manually since the way it's automatically stringified doesn't produce the intended result. I'm going to go ahead and close this, but we can reopen if you investigate further and have reason to believe this is an Awesomplete bug!