I have an Ext.Net Radiogroup and I have to get the selected value and then send that as a parameter to a controller action. Here is the Directevents I am attempting to use, but it doesnt' seem to work (I get null each time). Does anyone know how to get the value of the selected item?
.DirectEvents(de =>
{
de.Change.Url = Url.Action("GetItems");
de.Change.ExtraParams.Add(new Ext.Net.Parameter
{
Name = "Id",
Value = "App.myRadio.getValue() == null ? '0' : App.myRadio.getValue()",
Mode = ParameterMode.Raw
});
}),
To get an array of all the selected checkboxes/radio buttons on a radio group, you can do:
App.myRadio.getChecked();
This returns a list of all checkboxes and radio buttons that are selected on the radio group. If you only have radio buttons inside the radio group, it should return an array with just one item.
You can then get the value of the radio button like this:
App.myRadio.getChecked().length != 1 ? '0' : App.myRadio.getChecked()[0].getValue();
But this will always return a true-ish value (true, 'true', '1' or 'on') for a radio button. If you want the value on the label for that radio button, instead use the following:
App.myRadio.getChecked()[0].getFieldLabel()
Hope this helps!
Related
I have a grid with several columns. For three columns i used the column renderer. Each of the columns contains one button.
If i click one of those buttons, i want to replace the three buttons in that specific row with two other buttons. All the other rows should not be affected. Is this possible in a Vaadin grid?
Components in different columns don't know each other, as they are all defined in a separate scope (in the componentRenderer of their own column. You cannot define the Button outside of the componentRenderer as you found out in another question today). So the "obvious" solution won't work, where you add a clickListener on the Button to directly change the other buttons.
If you had one column with 3 Buttons inside then this would be much easier.
There is a way, but I see this more as a hack than as a solution. Because you need some extra implementation in the item class for this to work.
In the ComponentRenderer, you can add an if-statement where you look at some value of the item. In one case, you'll render button 1, in the other case you'll render the other button. And in the click listeners of the button you change that value in the item and refresh the dataprovider, so the componentRenderer is invoked again. It will now see the value on the item has changed, therefore displaying some other Button.
Here is some code to show what I mean:
// grid item class
public class Foo {
private boolean buttonPressed = false;
public Foo(){
}
public isButtonPressed(){
return buttonPressed;
}
public setButtonPressed(boolean buttonPressed){
this.buttonPressed = buttonPressed;
}
}
// adding of button columns
// do this 3 times for a test of your scenario.
grid.addComponentColumn(item -> {
if(!item.isButtonPressed()){
return new Button("Before Button was Pressed", click -> {
item.setButtonPressed(true);
grid.getDataProvider().refresh(item);
});
} else {
return new Button("Button was Pressed", click -> {
item.setButtonPressed(false);
grid.getDataProvider().refresh(item);
})
}
})
I was wondering if someone could shed some light on the issue I am having. I can't seem to get the data model updated when I use my custom input control in a cell. When using the standard sap.m.Input, updates to the data model are performed properly.
Here is the Plunker: https://plnkr.co/edit/GxE6F8DbW9DHqWjpfdO0
I have overrriden the getter for the 'value' properly to get the data from the entry field. Debugging in Chrome shows that this function is not called which I believe is the reason the data model is not updated.
getValue: function() {
var me = this;
var ef = sap.ui.getCore().byId(me.sId + '-ef');
return ef.getProperty('value');
}
Basically, there is a table with two rows and four columns. The first column uses my custom input. The second column has a custom button with an aggregation (additionalParameters) containing the bound data used in the first column. The third column uses a standard sap.m.Input and lastly the fourth column is again a custom button with the 'additionalParameters' aggregation bound to the data in the third column. When any of the buttons are pressed it fires an event which in turn updates the 'Sample' input field.
So, when I type something in the first column, tab out and press the respective 'PB1' button, only the original data from the model appears in the 'Sample' input field. If I type something in the third column, tab out of the field and press the respective 'PB2' button, the 'Sample' input field is properly set by the newly entered data implying the data model has been updated.
Edit
I can get the value from the Input no problem. Maybe I can clarify. The 'MyCustomInput' in cell 1 has 'value' bound to 'list>colOne'. The 'MyCustomButton' in cell 2 has the 'text' of the first item in aggregation 'additionalParameters' bound to the same 'list>colOne'. Any text entered into MyCustomInput does not update the model and thus does not update the 'additionalParameters' item. If I do the exact same thing but use a standard Input instead of MyCustomInput it works. As can be seen with the Input in Cell 3 and the button in Cell 4.
Thank you
May be you can provide more information. We have a simple example here
http://jsbin.com/yukujag/edit?html,js,output and it works on with getValue and setValue
sap.ui.define(['sap/m/Input', 'sap/m/Button', 'sap/m/VBox'],
function(Input, Button, VBox) {
Input.extend('MyInput', {
value: 'abc',
renderer: {},
getValue: function() {
return this.value;
},
setValue: function(v) {
this.value = v;
},
});
var oInput = new MyInput();
var oBox = new VBox({
items: [
oInput,
new Button({
text: 'Test',
press: function() {
alert(oInput.getValue());
}
})
]
})
oBox.placeAt('content');
});
Thanks
-D
I have the need to disable a button in my application provided nothing is selected or multiple rows are selected.
I created the following binding (extra code to debug it since it wasn't working)..
BooleanBinding singleDocIsntSelected =
Bindings.createBooleanBinding(() -> {
boolean result = documentTable.getSelectionModel().getSelectedItems().size() != 1;
return result;
}, documentTable.getSelectionModel().selectedItemProperty());
What happens to me is that when I select the first row, it fires, then if I CTRL + Click the same row, it fires again. So far all is well in the world. Then I Click the same row - nothing, or when I CTRL Click other rows nothing.
My button will stay in the wrong state.
However, if I also add a listener to the property:
ChangeListener<MyDTO> selectedItemsListener = (obs, ov, nv) -> {
boolean result = table.getSelectionModel().getSelectedItems().size() != 1;
System.err.println(result);
};
Then everything works properly.
Is there no other way to handle this?
You need the binding to be invalidated when the list of selected items changes, not when the selectedItem property changes. If one item is selected, that becomes the selected item: if you then select additional items, the selectedItemProperty will not change (it is still the first one selected out of all those selected).
Using your current idiom, just bind to the selected items list:
BooleanBinding singleDocIsntSelected =
Bindings.createBooleanBinding(() -> {
boolean result = documentTable.getSelectionModel().getSelectedItems().size() != 1;
return result;
}, documentTable.getSelectionModel().getSelectedItems());
or, more simply,
BooleanBinding singleDocIsntSelected =
Bindings.createBooleanBinding(
() -> documentTable.getSelectionModel().getSelectedItems().size() != 1,
documentTable.getSelectionModel().getSelectedItems());
Though it's probably cleaner to use Bindings.size() and IntegerBinding.isNotEqualTo():
BooleanBinding singleDocIsntSelected = Bindings
.size(documentTable.getSelectionModel().getSelectedItems())
.isNotEqualTo(1);
I have a GridPanel named GridPanel1 and a button to remove the selected row of the GridPanel,
I want to get the selected row id by clicking a ext button and send the id to a directMethod.
My code is:
var removeEmployee = function () {
// CompanyZ.Delete(id); // Here I need the GridPanel selected row id
console.log(mygrid);
}
Please can anyone help me?
Please use:
grid.getSelectionModel().getSelection()[0].getId()
I have a drop down box in ruby on rails that allows a date to be entered. And there is a box beside it to indicate that no date will be entered.
When this box is ticked it changes the default value of the date to nil. However the user can still enter a date on the drop down boxes.
When the box is ticked I want the drop down to be readonly or uneditable how can I do this?
EDIT
function BlankOutStartDates() {
if (document.getElementById("service_unknown_start_date").checked == true)
{
document.getElementById("service_start_date_1i").selectedIndex = 0;
document.getElementById("service_start_date_2i").selectedIndex = 0;
document.getElementById("service_start_date_3i").selectedIndex = 0;
}
}
I want to add the addition javascript to make the drop down box read only if the box is ticket
I would actually do this in jQuery. Suppose your checkbox has class "no-date", and your select boxes all of the class "date-select". Then you could do this:
jQuery(".no-date").change(function(){
//Check if the box is checked
if(this.is(':checked')){
jQuery(".date-select").attr("disabled", "true");
} else {
jQuery(".date-select").removeAttr("disabled");
}
});
You'll want to double check "this.is(':checked')" is correct, but I think that will work.
This uses the "disabled" parameter of select tags: http://www.w3schools.com/tags/tag_select.asp