Smart GWT how to select item in ComboBoxItem - gwt

I have what seems like it should be a really simple problem, but somehow it is not. SmartGwt has a way of taking something easy and making it overly complicated!
I have a ComboBoxItem populated by a LinkedHashMap. All I want to do is to be able to programmatically select a row/value to display. In plain GWT, this would be something like:
listBox.setSelected(1)
I have searched and searched, and I have come up empty. Please someone help!!!

Suppose your map has values like
items.put(1,"a");
items.put(2,"b");
ComboBoxItem listBox = new ComboBoxItem();
listBox.setValueMap(items);
Then
listBox.setValue(1) will display "a" in listBox
listBox.setvalue(2) will display "b" in listBox

You Can set value's for drop down in Combobox item through setValuMap(String array[])
String []valueMap = {"A","B"};
comboBoxItem.setValueMap(valueMap);
this will set the value in string array to combox box. You can set value programmatically through setValue(String value) function.
comboBoxItem.setValue("A");
http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/form/fields/ComboBoxItem.html

Related

Is it possible to convert a string to the name of a list?

Before we come to the actual question, I'll need you to understand my App.
I have a function add() which feeds integers based on the user's input into a list. This list of integers is fed into a function avg() which calculates the average of all the integers inside of the list.
This list however, is bound to a widget which can be added infinite. But before a title for that widget must also be provided by the user.
Imagine it like that: You click on a floatingActionButton and a TextField opens. In that TextField you type in a title. After you submit the title a Box is crated with that title.
Inside this Box you have the possibility to click a Button which opens a new TextField. In that textField you type in an integer between 0-15 which then is added to the list bound to the widget.
That's why I need a new list of integers to be created, whenever I create a the users creates a new Widget.
That's why I was wondering if there is a way to just take the String of the title (lets say 'my awesome title') and use that to define a new list with that string (my thoughts in code are below).
Something like this:
String title = 'title';
List<int> 'title' = [];
Everything I found regarding this topic, didn't really covered the answer I was looking for. So please excuse me if this question was asked in a similar way before. I probably didn't understood it, hopefully you can help me out better. :)
If it is not possible to convert a String to a list name, I would love to hear about a different technique which would solve the problem explained.
If I understood you correctly You want to save the value as a identifier/variable name and use that for fetching other values? like list of integers.
In that case thing which might suit your case would be Map or key/value pairs.
Lets say you got a String from server or any other way.
String title = await getStringFromServer();
List<int> data = await getIntegersfromSomewhere(title);
Now you might want the map to come in action. you can save these values in map.
final Map<String,List<int>> _map = Map();
map[title] = data;
Now your map will contain whatever string you got from the server or from anywhere. and corresponding list of integers.

UIPickerView custom title

I have an array that I use to populate my pickerView, a simple string array. The issue is that I need the first item to be something like "Choose team".
The only way I have achieved that is the add the first item in the array to be "Choose team", but this messes up the array structure for me and I wonder if there is another way of doing this.
So, can I add a default value to a UIPickerValue, if no: how would you have solved this issue?
There is no easy way to add a default value. You can duplicate the array and add the string to the duplicated version for display but then you have to be careful about indexing issues. If the array's value changes programmatically, it can be a disaster. This duplication thing is not a good design anyway.
Alternatively, you can add a fixed label on right side of each picker values. Here is the example
Fixed labels in the selection bar of a UIPickerView

Tooltip on combox Item

I want a tool tip on the drop down list for combox items. I have a combobox and showing combobox item in that combobox on selected index change of drop down, but it is note helping me too much.
Since my dropdown size is small, and items in the dropdown are very big, it's become difficult for users to select the proper value by seeing this.
If tooltip shown on the individual item, it could be very useful.
If any budy knows answer , Please reply.
Use the ToolTip class for this. An example in code would be:
ToolTip toolTip = new ToolTip();
toolTip.Show(comboBox1.SelectedItem.ToString(), comboBox1);
You can then tie this code to the comboBox1_SelectedIndexChanged event handler.
NOTE: Your ComboBox name may differ from mine.

GXT 3 spinnerField validation

I want to validate that user cannot change spinner value manually by typing in text box of spinner.
For example a field sales multiple = x which I fetched from server not fix.
and displays a spinner field with limitation of like bellow
spinner.setMinValue = x
spinner.setIncrement = x
spinner.setValue = x
so user forcefully select a value which is multiple with x. e.g. if x=3 the user have to enter 3,6,9... and so on.
So here my issue is if I type a 2 in spinner field text box. GXT widget accept that value.
Posible solutions:
Is there any predefined properties of spinnerfield that i forget to set it?
Is there any predefined validator for this?
Can I set text box of spinner field read only by css so user cannot focus on text box but still change a value.
If none of above how to achieve manually?
i've searched a bit in the different classes and I don't see either a precise method which would set what you want.
Don't know about one, and even with one, a validator doesn't change the value in the input field, but maybe it's enough for your needs.
You can disable the text input by calling setEditable(boolean) on the spinnerfield (testSpinner.setEditable(false);)
Maybe you could search around the IntegerPropertyEditor, I haven't tried but as long as a new Spinner is like this:
SpinnerField<Integer> testSpinner = new SpinnerField<Integer>(new NumberPropertyEditor.IntegerPropertyEditor());
you can seen that there is another Constructor for IntegerPropertyEditor, which takes a "NumberFormat" param, but there is no NumberFormart() constructor, so I'm not sure about how you create your own one, but that could be an idea (to format numbers in the input to be a multiple of the increment).
The last option would be that Sencha forgot this possibility and that you should report this as a "bug" on the forum ?
Hope to have helped a bit, good luck :).

Dashcode - how to register and use my own filterPredicate procedurally

In my Dashcode mobile app I have a listView that is bound to a datasource. By default it shows everything in the datasource. If I add a search field the user may limit the list to just the records that match their search text.
I want to create my own preset searches attached to buttons that would be able to load a list view and show only the records from my datasource that match my custom search.
It seems like this ought to be possible, but so far I haven't figured out how to register my own filterPredicate and then use it.
I'm guessing this is what I want to do because it seems like this is what the search field part does.
Has anyone figured out how to do this?
Any help would be appreciated
According to the dashcode starter section, you could use something along the lines of:
itemDescription = Class.create(DC.ValueTransformer, {
transformedValue: function(value){
return "Page: " + value;
}
});