How to do Multiple select in thymeleaf? - thymeleaf

I'm using thymeleaf for my UI part. I have a query.I have created a student and linked with different department. now while showing the student detail, i have to show the all the department and as well as mapped department in the select box which allows the multiple selection of the department. i have no idea how to do that can some one help me to fix this issue.

This snippet should do the work:
<select id="multiSelectElementsSelected"
name="multiSelectElementsSelected"
multiple="multiple"
th:field="*{departments}">
<option th:each="department,row : ${collectionOfDepartments.values()}"
th:value="${department.value}"
th:text="${department.label}"></option>
</select>

Related

MVC razor DisplayFor a list

I have a view, with a list that i have populated. I want to have a DisplayFor that will change and show what is selected in the drop down list.
This is my view so far. I have tried googling the problem, and after a few hours of reading through pages i cant find anything specific to what i am trying.
<select id="Test1">
<option value="test">Role1</option>
<option value="test">Role2</option>
<option value="test">Role3</option>
<option value="test">Role4</option>
</select>
#Html.DisplayFor(Test1)
But of course this will just not work. And i really dont know what to try now.
I tried using Test1.selected, and i also tried having Test1 as a model then pass a list through, but it would require a page to be refreshed.

Select2 multi select not working

Hi i used select2 (https://select2.github.io/) in my site and it's not working there. on click classes etc changed like example one but it didn't shows the select box options and there is no error in console.
I am using multi select option of it.
Here is code:
<select name="xo_pages_show_name[]" class="spages" multiple="true">
<option value="4">Optin Demo</option>
<option value="2">Sample Page</option>
</select>
Here is jquery code in custom file and included in footer.
$(".spages").select2({
placeholder: "Select Pages"
});
Here is the frontend screenshot: http://i.prntscr.com/0d079920de3b4e3081a153b45cb9753a.png
Any help ?
No it was just problem with z-index.
Main container z-index was more than inner one. so it was not showing

i18next and JQuery doesn't work in form's drop down list

I am using JQuery Mobile for a mobile website, and for localization I am using i18next. I have an issue in my form, here it is :
<form id="form" method="POST" action="webservices/action.php">
<select id="subject">
<option value='0' data-i18n="contact.email" selected></option>
<option value='1' data-i18n="contact.name"></option>
<option value='2' data-i18n="contact.object"></option>
</select>
</form>
The localization works fine, I have the desired text displayed. However, the first option is not displayed and it is not possible to select it (it is possible to select other options). When looking at the select object in Javascript, it seems that the correct index is selected., therfore it is a UI problem.
I don't have any problem when not using i18next.
Anyone have an idea how to fix this issue ?
I found a workaround. I noticed that when I sent my form and reset it, the dropdown list was correclty displayed. So after initializing i18n, I used this:
document.getElementById("form").reset();
The form is now displayed correctly.

angular & ui-select2: showing preselected value doesn't work

When using the ui-select2 (https://github.com/angular-ui/ui-select2), the preselected option is not shown properly.
I created a plunkr: http://plnkr.co/edit/Ek86jUciPo7rgBnbKdFc
When the page is loaded, the model of the select is set to the second option. And somehow, it is properly set in the select box, see: https://dl.dropboxusercontent.com/u/1004639/stackoverflow/screenshot-select2.png. But the value is not shown above the text box. Or in the select box when the select box is closed.
PS: I tried it without ng-options. Same problem.
I can get it working using ng-repeat and ng-selected. Unfortunately, though, when you use ng-repeat, you can only bind to a string. It's not ideal, but the choice does start out pre-selected.
Here's a working http://plnkr.co/edit/jodn35fvUQpdD2d5BpoC
<select ui-select2="" ng-model="selectedId" >
<option value="">Choose...</option>
<option ng-repeat="option in options" value="{{option.id}}" ng-selected="{{option.id == selectedId}}">{{option.name}}</option>
</select>
And I updated the JS to add this line:
$scope.selectedId = $scope.selected.id;
https://github.com/angular-ui/ui-select2#working-with-dynamic-options
ui-select2 is incompatible with <select ng-options>. For the best results use <option ng-repeat> instead.

Symfony search form

I use symfony 1.4.12 with Zend Lucene. And I make custom search, I have field like category, country...I create module and I have MysearchSucess.php and there I write hardcode, like :
<select name="ads_country" id="ads_country">
<option value="AF">Afghanistan</option>
<option value="AX">Ă…land Islands</option>
<option value="AL">Albania</option>
</select>
etc... But there are in symfony nice widget like sfWidgetFormI18nChoiceCountry;
Or for examle, if user add category, I will need to add new category in code manualy... Is it possible to use widgets in my case? how to organize it right without hardcode?
Thank you!
Ok, I read this and all ok!

Resources