Need help with th:selected!

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Need help with th:selected!

Hi there, new to the forum. Hope someone can help me out with an issue I am having with <select> in thymeleaf.

I have a list of <option> in my <select> element. I want to preselect one of them that matches the context I am passing to the template. It looks like this:

                <select name="bankBranch" title="Select Bank Name">
                    <option>BANK CENTRAL ASIA (BCA)</option>
                    <option>BANK NEGARA INDONESIA (BNI)</option>
                    <option>BANK RAKYAT INDONESIA (BRI)</option>
                    <option>BANK TABUNGAN NEGARA (BTN)</option>
                    <option>CIMB NIAGA</option>

I want to preselect the option that matches with ${user.vendor.bank_branch}. How can I do this?

Any help would be much appreciated! Thank you.
Reply | Threaded
Open this post in threaded view

Re: Need help with th:selected!

th:field="${user.vendor.bank_branch}" in select and some th:value in ur options.
If bank_branch == some option's value - it will be automaticaly selected.