jquery-select2 / Copy selection from one field to another - jquery-select2

I adapted some javascript to work with jquery “select 2” plugin in order to duplicate the selected fields to another part of the form. The only issue is that I am not able to get this to function with the new version of "Select 2" (v.4.0.3). Apparently some methods have been deprecated in the new version and this breaks my code.
Does anyone have insight how I may be able to duplicate form inputs with the latest version?
Here is my working example of the old select 2 version (v3.5) in jsfiddle. I would like to try and emulate this with the latest version.
Working in Select2 v3.5
http://jsfiddle.net/jinch/0oao3wo0/
Broken in Select2 v4.0.3
http://jsfiddle.net/jinch/jr3L0q4f/1/
And here is the basic code I pieced together.
$('#shipping_state').select2('val', $('#billing_state').select2("val").toString());
Any suggestions welcome.
Thank you.

Ok... figured it out if anyone else needs.
Here is the how to bind and copy the value to the other field.
$("#shipping_state").val($("#billing_state").val()).trigger("change");
Working example:
http://jsfiddle.net/jinch/jr3L0q4f/8/

Related

Vaadin 12 ItemLabelGenerator of ComboBox when used in grid ComponentRenderer

Today I have upgraded from Vaadin 11.0.2 to 12.0.0 - Everything went smooth, except one thing:
In a grid of mine where I have a rendered column to show a ComboBox, there is a strange issue with the ItemLabelGenerator. I defined it as follows:
grid.addColumn(new ComponentRenderer<>(gridItem -> {
ComboBox<MyObject> comboBox = new ComboBox<>();
comboBox.setItems(myObjectsService.findAll());
comboBox.setValue(gridItem.getMyObject());
comboBox.setItemLabelGenerator(MyObject::getName); // MyObject::getName returns String
// comboBox.addValueChangeListener omitted
return comboBox;
}))
.setHeader("MyObject")
.setId("myObject");
This has been working fine in Vaadin 11.0.2 but now the item-labels are displayed as package.path.to.myobject.MyObject#41d8d522 and not the actual name of gridItem.getMyObject();
When I click on the ComboBox to show all options, the labels are correct! but as soon as I select one, it turns into the aforementioned wrong string.
Important detail: for testing reasons I have now added a similar ComboBox with the same setup into a simple VerticalLayout (AKA not in a grid), and there everything works perfectly fine. That is why I think the issue is with the ComponentRenderer somehow and not with the ComboBox alone.
Is this a bug, or have I missed something when upgrading to 12.0.0 ?
In the vaadin blog post about the new release of Vaadin 12, I see that there is one known breaking change, and it has to do with ComboBox:
If you are coming from Vaadin 10 or 11, you should update the platform dependency in your project build file. The only breaking change we introduced was because ComboBox now supports server-side lazy-loading. If you are using filtering with a ComboBox see instructions on fixing the possible compilation issue.
However, no filtering whatsoever is involved in my case.
This answer was written by Diego Sanz Villafruela in the Vaadin Forum, where I raised this exact issue too.
I created an example similar to yours and I discover that the order in
which you set the value and the ItemLabelGenerator matters.
You should put comboBox.setValue after setting the
comboBox.setItemLabelGenerator.
Otherwise the method String.valueOf(obj) will be called the first
time, giving you the object's representation (MyObject#41d8d522) and
not the name.

Zkoss listbox+frozen+hide_column

I use listbox with one frozen column. it's working fine but if i hide last (only last) column , i'll get problem with listbox's content. Header scrolls normaly but all rows of listbox appear.
ZK-8.5.2.1-Eval
I use olde frozen - listbox.setAttribute("org.zkoss.zul.frozen.smooth", false);
I'd suggest to try the latest version ZK 8.6.0.1 first? The release notes (8.6.0 / 8.6.0.1) indicate errors being fixed regarding frozen and listheaders maybe the problem doesn't happen anymore with the latest version.
It the problem still exists it would help if you can provide a reproducing/runnable example e.g. on zkfiddle.org Please, save and post the link or url-path here.

FastReport4: Refresh Dataset

My Report.ShowPreparedReport didn't recognize a new addition to my frxDBDataset.
So, I was building 1 report using TfrxDBDataset linked to a TVirtualTable.
Previously only 10 fields stated in Report1.fr3 and it works well.
I do the SaveAs from Report1.fr3 to Report2.fr3 in designer mode
Get back to my Delphi and add 1 new field "tec" in my TVirtualTable
Go back again in ReportDesigner (file Report2.fr3) and see that my new "tec" field is listed in Data tree.
Add the "tec" field to the report.
Preview while on designer and it was normal.
Run the program and call to preview report, it says "field 'tec' cannot be found" or something like that.
Anyone got solution?
Thanks
Please Try.
TVirtualTable.Refresh;
frxDBDataset.FieldAliases.Clear;
When you clear aliases then call Designer
FastReport automatically updates aliases.
That was the perfect solution for me.

Android - What does question mark signify in searchable.xml?

I'm debugging SearchableDictionary sample on android 4.0. In searchable.xml, what does question mark signify in this attribute, android:searchSuggestSelection=" ?"?
Here is the snippet :
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/search_label"
android:hint="#string/search_hint"
android:searchSettingsDescription="#string/settings_description"
android:searchSuggestAuthority="com.example.android.searchabledict.DictionaryProvider"
android:searchSuggestIntentAction="android.intent.action.VIEW"
android:searchSuggestIntentData="content://com.example.android.searchabledict.DictionaryProvider/dictionary"
android:searchSuggestSelection=" ?"
android:searchSuggestThreshold="1"
android:includeInGlobalSearch="true"
>
Thanks.
It stands for the query typed by the user. See the docs
android:searchSuggestSelection [String]
This value is passed into your
query function as the selection parameter. Typically this is a WHERE
clause for your database, and should contain a single question mark,
which is a placeholder for the actual query string that has been typed
by the user (for example, "query=?").
Alternate
android:searchSuggestSelection="word MATCH ?"
also had a problem on this one, SearchableDictionary sample. cannot find the Resource folder because R.java is not generated which is probably the same problem you were experiencing that's why your debugging the XMLs. this is the solution that worked for me. link
Right-click on your project
Choose Properties
Choose Android in the left menu
Tick a box next to the appropriate Project Build Target.*****
Click Apply and OK
My additional instructions:
*****Choose build higher than API 10 or starting from API 11. If you choose lower than 11 you will still get the error. This worked for me. tried most of the suggestions ahead of this. finally solved it.

selectToUISlider setting value incorrectly

I have a standard <select>..</select> element with which I have a slider created by selectToUISlider()
The problem is that when the slider moves the option in the dropdown does not change. Additionally it sets selected="selected" on each element as the slider is moved so that when the form is submitted multiple values are POSTed emulating a multiple select option.
I've spent ages trying to get to the bottom of this but no luck. Does anyone have any ideas?
I came across the same problem when trying to achieve similar functionality as mentioned by you.
The problem is whenever a slider is moved it keeps setting the "selected" attribute of the select list without clearing up previously selected item. I have added a script to clear previously selected option items before setting the new one as selected.
Look/search for the text at line number 92(..ish) of the jquery script file.
//control original select menu
var currSelect = jQuery('#' + thisHandle.attr('id').split('handle_')[1]);
currSelect.find('option').eq(ui.value).attr('selected', 'selected');
and insert this code between 2 lines...
currSelect.find('option[selected]').removeAttr('selected');
so final code should look like this...
//control original select menu
var currSelect = jQuery('#' + thisHandle.attr('id').split('handle_')[1]);
currSelect.find('option[selected]').removeAttr('selected');
currSelect.find('option').eq(ui.value).attr('selected', 'selected');
I hope it helps.
Feel free to ask any further question.
I know this is quite old but I recently stuggled with this and maybe my solution helps someone. I had this same problem when using more recent versions of jQuery (>jQuery 1.6.1) and JQueryUI and trying to use selectToUISlider with them.
I found my solution (using properties insted of attributes) just replacing in the selectToUISlider.js script, in line 98
This
currSelect.find('option').eq(ui.value).attr('selected', 'selected');
for this
currSelect.find('option').eq(ui.value).prop('selected', true);
You can find the "Why" on this answer, which helped me to find this solution:
https://stackoverflow.com/a/5876747/2285806
You can read also the jQuery API entry for prop() to find more information and read important notes on browser backwards compatibility:
http://api.jquery.com/prop/

Resources