Quantcast

Decoupled logic odd behaviour

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Decoupled logic odd behaviour

dani
Hi, I'm trying the decoupled logic feature, which is really cool btw. The problem though is that there seems to be a bug or something, here's my edit.html:

Choose your language
<select name="languageId" class="form-control" id="language">
    <option value="0">XXXX</option>                   
</select>

And here's my edit.th.xml:

    <attr sel="#language/option" th:remove="all-but-first" th:each="language : ${languages}" th:text="${language.name}" th:value="${language.name}" />

Here, Thymeleaf fills in correctly the value tag, but the option's text ramins intact... :?

 Note it works fine if I place that logic inside the .html, in the traditional way:

 <option th:each="language : ${languages}" th:text="${language.name}" th:value="${language.name}" />

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decoupled logic odd behaviour

danielfernandez
Administrator
Your problem is that th:remove="all-but-first". That type of removal removes "all but the first CHILDREN" of the host tag, and in this case that means the first node of your <option> tag, the Text containing "XXXX" is not removed and therefore gets output.

If you want to use th:remove="all-but-first" there, you should be adding it to the <select> tag, not the <option>.

Your non-decoupled code works because you are not adding that attribute there.

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Decoupled logic odd behaviour

dani
Hi Daniel, thanks for that, I think the key point, as you mentioned, is that th:remove="all-but-first" removes all children except the first one. So I managed to make it work with the folllowing:

    <attr sel="#language" th:remove="all-but-first">
      <attr sel="/option" th:each="language : ${languages}" th:text="${language.name}" th:value="${language.id}" />
    </attr>

I don't know If there are other ways to achieve the same results, suggestions are welcome.

Thanks again!
Loading...