I want to create Vaadin drop down with 2 separators in it. I couldn't find a way to implement that, can anyone help me to solve this issue?
This is the way I want to display my drop down:
Option 1
Option 2
------------;
select 1
select 2
-----------;
group 1
How can I do that?
There is no built-in way to add separators to selects. The only way I can think of is to add an item with the desired separator as its caption. For example if you use the default caption (item id) select.addItem("-----"); should be enough. This should work for both ComboBoxes and NativeSelects.
You can implement a new Vaadin component including the client behaviour, but this is not an easy solution. This page https://vaadin.com/book/-/page/gwt.html of "Book of Vaadin" and Vaadin forum can help for that.
Also, creating your own component using existing components is another solution. You can implement a special combobox which takes values of String or Component arrays. The way of doing this is using Vaadin panels, layouts and windows with size and locations and click listeners.
I haven't tried it myself but give a go at NativeSelection dropdown.
You can always do
{select.addItem("-----");}
Once I also wanted a do something like that but there was no proper way to do that with Vaadin. I actually created a Vaadin widget extending the Combo Box. In the client side widget of Vaadin they filter out the HTML content before adding items to the list. So Using the client side code I override that functionality and use HTML tag "" to add the line.
select.addItem("-----");
looks like the best way, I dont know about some other
Btw if you are reading items from some list you can combine that with some item counter and (itemsCount%n)==0 operator to set separator after 'n' items inserted :)
You can add the item to the selected (as mentioned before) and then disable the separators with some javascript:
add the item to the select.
cb.addItem("separator");
cb.setItemCaption("separator", "-------------");
execute the javascript
final String javascript = ""
"var selects = document.getElementsByTagName('select');"
"for(var j = 0;j < selects.length;j++){"
"var op = selects[j].getElementsByTagName('option');"
"for (var i = 0; i < op.length; i++) {"
" if(op[i].text == '" + separatorText + "') op[i].disabled = true;"
"}}";
Page.getCurrent().getJavaScript().execute(javascript);
Is there a reason that you use the ComboBox instead of the Select, because with the select you can do that.
Select select = new Select();
select.setItems("Option 1", "Option 2", "select 1", "select 2", "group 1");
select.addComponentAtIndex(2, new Hr());
select.addComponentAtIndex(5, new Hr());
Or you can use a MenuBar but it looks very diferent that the ComboBox.
menuBar = new MenuBar();
MenuItem menuItem = menuBar.addItem("Select");
menuItem.getSubMenu().addItem("Option 1");
menuItem.getSubMenu().addItem("Option 2");
menuItem.getSubMenu().addItem(new Hr());
menuItem.getSubMenu().addItem("select 1");
menuItem.getSubMenu().addItem("select 1");
menuItem.getSubMenu().addItem(new Hr());
menuItem.getSubMenu().addItem("group 1");
Related
My application (based on Vaadin 8) has a CheckBox and a CheckBoxGroup wrapped in a HorizontalLayout.
CheckBox myCheckBox = new CheckBox("My Checkbox");
CheckBoxGroup<String> multi = new CheckBoxGroup<>("Multiple Selection");
multi.setItems("Many", "Muchos", "Monta");
multi.setCaption(null);
multi.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
checkBoxLayout.addComponents(myCheckBox, multi);
checkBoxLayout.setComponentAlignment(myCheckBox, BOTTOM_LEFT);
checkBoxLayout.setComponentAlignment(multi, BOTTOM_LEFT);
this.addComponent(checkBoxLayout);
The problem is that the horizontal alignment of the checkbox and the checkbox group is not correct.
Setting the checkbox group caption to null does not help either. I suppose that the checkbox group has some additional spacing which could cause this behavior. How can I make sure that the horizonal alignment is working as used with setComponentAlignment?
Update 1
The solution suggested by #ollitietavainen (using MIDDLE_CENTER) results in the following:
If you have nothing else than the checkboxes inside the HorizontalLayout, using Alignment.MIDDLE_CENTER seems to work better than BOTTOM_LEFT.
I tried removing the CheckBoxGroupState.primaryStyleName "v-select-optiongroup" style name than along with the alignment suggested by https://stackoverflow.com/a/65180983/12854146 I have the following code
HorizontalLayout checkBoxLayout = new HorizontalLayout();
checkBoxLayout.setMargin(true);
CheckBox myCheckBox = new CheckBox("My Checkbox");
CheckBoxGroup<String> multi = new CheckBoxGroup<>("Multiple Selection");
multi.setItems("Many", "Muchos", "Monta");
multi.setCaption(null);
multi.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
multi.removeStyleNames("v-select-optiongroup");
checkBoxLayout.addComponents(myCheckBox, multi);
checkBoxLayout.setComponentAlignment(myCheckBox, MIDDLE_CENTER);
checkBoxLayout.setComponentAlignment(multi, MIDDLE_CENTER);
you may have a similar output if you do not remove the style name "v-select-optiongroup" from multi and instead you add it to your checkbox with
myCheckBox.addStyleName("select-optiongroup");
I have a custom section, with a custom tree.
I'm having a bit of trouble understanding how you set the correct behavior when:
You click a node in your tree to edit it.
You click a menu item on a node like "Create"
In my solution I'm using the same view to edit and create a record.
In my tree this is how a node is generated.
var routeToView = "rewards/rewardsTree/editcampaign/campaign-" + campaign.Id.ToString();
var campaignNode = CreateTreeNode("campaign-" + campaign.Id.ToString(), id.Split('-')[1], queryStrings, campaign.CampaignName, "icon-folder color-yellow", true, routeToView);
This is producing the route I want: (the name of my html file is editcampaign.html) and it is also passing "campaign-6"
/umbraco#/rewards/rewardsTree/editcampaign/campaign-6
When a user clicks the create 'menu Item' on the node - I want to send them to the same URL but just with a diffrent Id for example:
umbraco#/rewards/rewardsTree/editcampaign/brand-1
and I don't want it to pop up out of the side
This is what I have tried so far:
//This finds the view, but it comes up in a dialog also how do I pass the Id (brand-1)
MenuItem mi = new MenuItem("editcampaign", "Create Campaign");
menuItemCollection.Items.Add(mi);
//Also Tried this finds puts a whole another umbraco UI inside a dialog
mi.LaunchDialogView("#rewards/rewardsTree/editcampaign/brand-1", "TITLE GOES HERE");
Can anyone point me to the fullest documentation for Menu's trees and navigation around the back office in general?
I believe there is an option to set view path on the "Create" menu item, which makes it open normally? Also, wouldn't it make more sense to have your path like /view/path/here/id ? Then when you create a new item just send 0 as id. Umbrangular on Github is a project with great examples of custom sections and views.
EDIT: Here's an example
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
MenuItem createCategory = new MenuItem("createcategory", "Create Category");
createCategory.AdditionalData.Add("ParentCategoryId", id);
createCategory.NavigateToRoute("/path/to/view/category/0");
createCategory.Icon = "add";
menu.Items.Add(createCategory);
return menu;
}
Gerrit used to show the ID as the first column in the UI. I'm on version 2.9 (yeah, I know, oldish, but we can't upgrade at the current time), and it's no longer visible. I know I can click on a change and see the ID or hover over a change and see it in the URL in the browser status line, but I really need to be able to see a bunch of them at a glance.
Is there any way to augment the URL I use to add it?
Go to your preferences (i.e. your-gerrit.com/#/settings/preferences) and check the Show Change Number In Changes Table option.
As I can see in this issue it was introduced in 2.10 but I remember using it earlier, if I'm not mistaken.
EDIT:
The change that itroduces it is here and it's included in 2.10. You will have to update in order to get the Change-Id column in the list.
EDIT 2:
I have created a simple JS script that will show the column with ChangeId. Just paste it to the URL bar when you are viewing the changes list:
javascript:var cols = document.getElementsByClassName("cSUBJECT"); for (var i = 0; i < cols.length; i++) { var id = cols[i].children[0].getAttribute('href').substr(cols[0].children[0].getAttribute('href').lastIndexOf('/') + 1); cols[i].insertAdjacentHTML('beforebegin', '<td>' + id + '</td>'); } document.getElementsByClassName("iconHeader")[0].insertAdjacentHTML('afterend', '<td class="iconHeader"></td>');
You can add it as bookmark if you wish and click it when you want change numbers displayed :-) Might need some tweaking, though.
I have a table which displays results like the image posted below. Now I need to do some actions on each row by selecting it. There are two options I can think of,
1) We can provide a radio button for each row & a drop down on the right side to perform an action. But here i need to generate this code dynamically from a javascript file like below
function getMessage(result){
for (var j = 0; j < result.invocationResult.resultSet.length; j++) {
var tmp = "<tr>";
var resSet = result.invocationResult.resultSet[j];
for(res in resSet){
tmp += "<td>" + resSet[res] + "</td>";
}
$("#mytable > tbody").append(tmp+"</tr>");
$('#AppBody').hide();
$('#AuthBody').hide();
$('#ResTable').show();
}
}
2) Provide a link to a particular item in the row like Dispute Number & when clicked it should take me to another page where I can perform those action with a drop down. But here the links should be applied dynamically to the items in the rows. As per my knowledge we should not navigate using href as i am using worklight.
Please help me with approach and also examples.
Thanks.
So I'm not sure what is the issue you are facing with option 1...
As for option 2,
There is no problem navigating to another "page" using Worklight and jQuery Mobile, as long as you're doing it responsibly (definitely not use href). That is, not lose the Worklight context, at which point stuff will stop working.
The idea is this:
In the app's index.html you (will/should) have a <div data-role="page"> and in the case of Worklight, you will need to switch its contents with another from some other HTML file.
Here's a simplified Worklight 6.2 sample project: https://github.com/IdanAdar/Multipage-Navigation-Using-jQM
In the HTML:
load page1
In the JavaScript:
function changeToSomePage() {
$(':mobile-pagecontainer').pagecontainer('change','somepage.html');
}
In these code I have a strange situation:
#foreach (var subs in getSubscriptionTypes())
{
<p>#Html.RadioButton(subs.LengthMonths.ToString(), subs.Price) #subs.LengthMonths</p>
}
I get properly all of subs, but radiobuttons behave very strange - I can check all of radiobuttons, but I want to check only one (one is true, then rest is false). How to repair it?
Regards.
The first parameter of each radio button needs to be the same for them to be mutually exclusive (see this demo).
So try:
<p>#Html.RadioButton("subtype", subs.Price) #subs.LengthMonths</p>
For a better user interface, you could also add a label element using #Html.Label(...) so that the user can click on the text to select the radio:
<p>
#Html.RadioButton("subtype", subs.Price, new { id = "subtype-" + subs.Price })
#Html.Label("subtype-" + subs.Price, #subs.LengthMonths)
</p>