Unable type values in input field RadioButtonGroup ComponentRenderer - vaadin

Hi I am trying develop a feature something as below in the picture. When I am selecting option(Ex: Monthly) from left panel right side panel will automatically render the required components. When I select the option from the right side panel I want to type the required values in input box. When I click on input box I am not getting the focus to type. Facing same issue for Combobox as well. Attaching some code snippet as well.
radioGroup = new RadioButtonGroup<>();
radioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
radioGroup.setItems("None", "Daily", "Weekly", "Monthly");
radioGroup.setValue("None");
VerticalLayout leftLayout = new VerticalLayout();
VerticalLayout rightLayout = new VerticalLayout();
radioGroup.addValueChangeListener(event -> {
if (event.getValue().equalsIgnoreCase("Monthly")) {
monthlyRadioGroup = new RadioButtonGroup<>();
monthlyRadioGroup.addThemeVariants(RadioGroupVariant.LUMO_VERTICAL);
monthlyRadioGroup.setItems("Day", "The");
monthlyRadioGroup.setValue("Day");
monthlyRadioGroup.setRenderer(new ComponentRenderer<>(item -> {
if ("Day".equals(item)) {
HorizontalLayout dayLayout = new HorizontalLayout();
IntegerField dayField = new IntegerField();
dayField.setValue(1);
dayField.focus();
dayField.setAutofocus(true);
dayField.setWidth("50px");
IntegerField monthField = new IntegerField();
monthField.setValue(1);
monthField.setWidth("50px");
dayLayout.add(new Label("Day"), dayField, new Label("of every"), monthField, new Label("month(s)"));
dayLayout.setAlignItems(Alignment.CENTER);
return dayLayout;
}else {
HorizontalLayout weekDayLayout = new HorizontalLayout();
ComboBox<String> weekNum = new ComboBox<String>();
weekNum.setItems("First", "Second", "Third", "Fourth", "Last");
weekNum.setValue("First");
weekNum.setWidth("100px");
ComboBox<String> day = new ComboBox<String>();
day.setItems("Day", "Weekday", "Weekend Day", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
day.setValue("Friday");
day.setWidth("120px");
IntegerField monthField = new IntegerField();
monthField.setValue(1);
monthField.setWidth("50px");
weekDayLayout.add(new Label("The"), weekNum, day, new Label("of every"), monthField,
new Label("month(s)"));
weekDayLayout.setAlignItems(Alignment.CENTER);
return weekDayLayout;
}
}));
rightLayout.add(monthlyRadioGroup);
}
});

It worked by adding below snippet in all the input fields
dayField.getElement().addEventListener("click", e -> dayField.focus());

Related

Static list of data for dropdown list MVC

I want to have a static list of data in a model that can be used in a viewmodel and dropdown on a view. I want to be able to use it in this way in my controller:
MaintenanceTypeList = new SelectList(g, "MaintenanceTypeID", "MaintenanceTypeName"),
and access it in my view like this:
#Html.LabelFor(model => model.MaintenanceTypeID)
#Html.DropDownListFor(x => x.MaintenanceTypeID, Model.MaintenanceTypeList, "-- Select --", new { style = "width: 150px;" })
#Html.ValidationMessageFor(x => x.MaintenanceTypeID)
I am currently using a repository pattern for data in the database, but don't want to put this data in the database because it will never change. I still want it in a model though. Basically, my dropdown list should offer the following:
Value Text
-------------------------------------
Calibration Calibration
Prevent Preventative Maintenance
CalibrationPrevent PM and Calibration
Any help or examples of static lists using models/oop is appreciated
You can use a list initializer:
public static SomeHelperClass{
public static List<SelectListItem> MaintenanceTypeList {
get {
return new List<SelectListItem>
{ new SelectListItem{Value = "Calibration", Text = "Calibration"}
,new SelectListItem{ Value = "Prevent", Text = "Preventative Maintenance" }
,etc.
};
}
}
}
Hopefully I didn't miss a curly brace somewhere. You can google "C# list initializer" for more examples. I don't remember off top of my head what the actual collection to is for a SelectListCollection is, but I know there is a overload of DropDownList that accepts List as I often just have a collection of keyvaluepairs or something else, and then in my view I convert it to SelectListItems: someList.Select(i => new SelectListItem { Value = i.Key, Text = i.Value })
Note that another option is to place your values in an enum. You can then use a Description attribute on each enum value:
enum MaintenanceType {
[Description("Calibration")]
Calibration = 1,
[Description("Preventative Maintenance")]
Prevent = 2
}
Then you can do things like
Enum.GetValues(typeof(MaintenanceType )).Select(m=>new SelectListItem{ Value = m, Text = m.GetDescription()} ).ToList()
That last line was a little off the top of the head, so hopefully I didn't make a mistake. I feel like an enum is more well structured for what you're trying to do.

Wix populate listbox

I am trying to fill in a ListBox with CustomAction and it's not going well.
I try to figure out the session.Database.Tables but have no idea how to start.
I've created a listbox like this
<Control Id="ListBox1" Type="ListBox" Sorted="no" Indirect="no" Property="LISTBOXVALUESONE" X="10" Y="50" Width="150" Height="180">
<ListBox Property="LISTBOXVALUESONE">
<ListItem Text="ARGHH!" Value="1"/>
</ListBox>
</Control>
But I cant see the property in my verbrose log or anything about an table so I guess I have to create an table in customAction and populate it?
I see my ARGHH! in the list so it should exsist but how do I access the values? And add new ones?
Found more examples and stuff in C++ but i would like to make the CustomAction in C#
EDIT
Database db = session.Database;
string sqlInsertTemp = db.Tables["ListBox"].SqlInsertString + " TEMPORARY";
View view = db.OpenView(sqlInsertTemp );
view.Execute( new Record( new object[] { "LISTBOXVALUESONE", 2, "2", "One" } ));
view.Close();
Thanks to Christopher I got it to work with adding an value.
db.Tables["ListBox"] should remain the same and name the type not the id as i taught
And on this line view.Execute( new Record( new object[] { "LISTBOXVALUESONE", 2, "2", "One" } ));
you put your Listbox Property and then the placement of the value "one" we insert
The two "2"s is what I figure the placement we want it on and I already have an test value on 1
my "ARGHH!" so I put the new on 2 and dont know the details but...
I got an Table Update error and, one dublicate value error if i put 2,1 or 1,2 in the customaction!
I wrote a blog article about 5 years ago that might help you:
How DTF is going to help me become a better .NET Developer
You want to make sure your built MSI has a ListBox table otherwise the SQL won't work when it tries to generate the temp rows dynamically at runtime. If the ListBox element doesn't do this for you, the EnsureTable element will.
The actual C# looks something like:
Database db = session.Database;
string sqlInsertTemp = db.Tables["ListBox"].SqlInsertString + " TEMPORARY";
View view = db.OpenView(sqlInsertTemp );
view.Execute( new Record( new object[] { "TESTPROP", 1, "1", "One" } ));
view.Close();
Note this is an old code example and doesn't properly take advantage of using statements and IDisposable.
Add one record to list box:
private void AddRecordToListBox(string listBoxPropertyName, int index, string text, string value)
{
View view = session.Database.OpenView("SELECT * FROM ListBox");
view.Execute();
Record record = session.Database.CreateRecord(4);
record.SetString(1, listBoxPropertyName);
record.SetInteger(2, index);
record.SetString(3, value);
record.SetString(4, text);
view.Modify(ViewModifyMode.InsertTemporary, record);
view.Close();
}
Fill ListBox:
private void FillListBox()
{
var dict = SomeDict();
int index = 1;
foreach (var element in dict)
{
AddRecordToListBox(ListBoxName, index, element.Key, element.Value);
index++;
}
}
Clear ListBox
private void ClearListBox(string listBoxPropertyName)
{
var command = String.Format("DELETE FROM ListBox WHERE ListBox.Property='{0}'", listBoxPropertyName);
View view = session.Database.OpenView(command);
view.Execute();
view.Close();
}

SmartGwt: how to fetch the data in my listgrid

i have a list grid ,i am assiging the values to listGrid by some method in my app
like this
private ListGridRecord[] getData(UserRecord selectedClient) {
return new ListGridRecord[]{
new NameValueRecord(1, "US Siren", selectedClient.getClientsId()),
new NameValueRecord(2, "EN: Liste des identifiants", selectedClient.getClientId2()),
new NameValueRecord(3, "Account number", selectedClient.getClientId3()),
new NameValueRecord(4, "Partner number", selectedClient.getClientId4()),
new NameValueRecord(5, "REGON", selectedClient.getClientId5()),
new NameValueRecord(6, "US Siren*", selectedClient.getClientId6()) ,
new NameValueRecord(7, "TEST", selectedClient.getClientId7())
};
}
It works fine for me and shows the given values in the grid when the app runs .
Now i want to get these values which are displaying in the grid (Which user can also edit from the grid)
I can get the edited values like this
clientIdsGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
public FormItem getEditor(ListGridEditorContext context) {
ListGridField field = context.getEditField();
if (field.getName().equals("value")) {
NameValueRecord record = (NameValueRecord) context.getEditedRecord();
But if a user dont even click on any record and just click save to save the values as it is.
How can i then get the data which is in my grid .
I am trying these
clientIdsGrid.getRecord(1);
clientIdsGrid.getRecords();
but this gives me a listGrid/listGridRecord , how can i then fetch the individual data on each row from them .
grid.addEditorExitHandler may help. Within it u can use:
grid.getEditValueAsString(row num, Column name) for getting new edited value.
If no new it will return null.

wp7 ObservableCollection population

I'm using the AMCharts control and I'm trying to follow the example however, I'm not sure how I get the data out of my historyItemCollection (fig 1) into an Observable collection (fig 2)?
Fig 1:
from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;
Fig 2:
private ObservableCollection<TestDataItem> _data = new ObservableCollection<TestDataItem>()
{
new TestDataItem() { axis = "Mar", value=5},
new TestDataItem() { axis = "Apr", value=15.2},
new TestDataItem() { axis = "May", value=25},
new TestDataItem() { axis = "June", value=8.1},
};
In the historyitemcollection I have a date item that I would put in the axis value as well as a cost item that I would put in the value value (fig 2:)
How can I get my data into the observableCollection so I can use this chart control?
_data = new ObservableCollection<HistoryItem>
(
from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;
)
or if at runtime
var historyItems =
from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;
foreach (var item in historyItems)
_data.Add(item);

mvc pop up window

I have an mvc project with a jqgrid that has an editting column, my problem is when i Try to link the edit in each row to a pop up window, when I add the code below a window pop up opens but I recieve a 402 unothorized error, here is my code in the controller
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (
from item in items
select new
{
id = item.Id,
cell = new string[] {
"<A HREF=javascript: void(0) onclick=window.open
('/Views/viewname/Edit/'+"item.code+",'Edit','width=700,height=800'); >Edit</A>",
column2,
column3,
etc ...}
}).ToArray()
};
but if I just link the edit to a regular page through this code
var jsonData = new
{
total = totalPages,
page = page,
records = totalRecords,
rows = (
from item in items
select new
{
id = item.Id,
cell = new string[] {
"Edit " ,
column2,
column3,
etc ...}
}).ToArray()
I do not have any problems, I have a edit page which works fine if it is not a pop up window, has anybody faced this problem, or can anyone direct me to an example that is similar.Thnaks in advance
Have you tried with quotes around your href and onclick attribute values?

Resources