Xpages add values into Combo Box - combobox

I have a Combo Box and I would like to have the possibility to add new values in the Combo Box using a button and an Input Field. I tried with:
var value = getComponent("input").getValue();
getComponent("combobox").setValue(value);
but it is not working.
Thank you,
Florin

Use a viewScope e.g. viewScope.selectItems variable.
Use this viewScope as the selectItems list.
Add the initial values to it.
Later, add a additional new item to this viewScope and then it will appear in combobox's selection item list.
This is a working example:
<xp:comboBox
id="comboBox1"
value="#{sessionScope.test}">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:
if (!viewScope.selectItems) {
viewScope.selectItems = ["your","initial","values"];
}
return viewScope.selectItems;}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
<xp:inputText
id="inputText1"
value="#{viewScope.newItem}">
</xp:inputText>
<xp:button
value="Add to selectItems"
id="button1">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
viewScope.selectItems.add(viewScope.newItem);
viewScope.newItem = "";
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>

Related

adf: Using radio button in af:table for single row selection

This is not exactly an question, better to say - it's an answer with a little question: is there a better sollution? :)
Suppose you have a grid which contains some rows.
In each row you want to put a radio button, and only one radio button can be selected in the grid (each row has one radio button).
This radio button should be used not only to display selected row, but also to select a row by clicking radio button.
Selection is based on a table's field, which contains 1 for selected and 0 or null for all other rows.
Here is a short guide of achieving it:
(the obvious part)
add a column with a radiobutton:
<af:column headerText="#{bindings.DocsignersliteView2.hints.Isactual.label}"
id="c14" align="center">
<af:selectBooleanRadio label="Label 1"
id="sbr1"
value="#{row.Isactual}"
group="Isactual"
autoSubmit="true">
</af:selectBooleanRadio>
</af:column>
where Isactual - is the field in the table, which containts 1 for selected item and null for all others
Method onActual should be implemened to change values of the field Isactual in the table.
it appears to not work. Now it shows an actual row, but doesn't work when I select another radio button.
Naturally I tried to create ValueChangeListener, but never succeded - it didn't work correctly.
Ok, let's try to invert "onClickListener", as selectBooleanRadio doesn't posess such an attribute:
let's add clientlistener, javascript and server listener:
<af:resource type="javascript">
function onClickRadio(actionEvent) {
var comp = actionEvent.getSource();
AdfCustomEvent.queue(comp, "IsactualClickEvent",
{},
true);
actionEvent.cancel();
}
</af:resource>
<af:selectBooleanRadio label="Label 1"
id="sbr1"
value="#{row.Isactual}"
group="Isactual"
autoSubmit="true">
<af:clientListener type="click" method="onClickRadio"/>
<af:serverListener type="IsactualClickEvent"
method="#{viewScope.signerBean.onActual}"/>
</af:selectBooleanRadio>
it almost works, but there is one more 'tiny' detail: a field with 1 and 0 values (or 1 and null) - is not exactly the same as boolean, so this selectBooleanRadio needs a converter.
So we should create a class implementing converter:
public class BooleanDecimalConverter implements Converter {
public BooleanDecimalConverter() {
super();
}
#Override
public Object getAsObject(FacesContext facesContext, UIComponent uIComponent, String string) {
if (string == null || string.isEmpty())
return null;
return "true".equals(string) ? BigDecimal.valueOf(1) : BigDecimal.valueOf(0);
}
#Override
public String getAsString(FacesContext facesContext, UIComponent uIComponent, Object object) {
if (object == null)
return null;
String result;
if (object instanceof Boolean){
result = object.toString();
}
else if (object instanceof BigDecimal) {
BigDecimal num = ((BigDecimal)object);
result = num.compareTo(BigDecimal.valueOf(1)) == 0? "true" : "false";
}
else {
result = "false";
}
return result;
}
}
then register the custom converter in the application's JSF configuration file (faces-config.xml):
<converter>
<converter-id>custom.BooleanDecimalConverter</converter-id>
<converter-class>common.utils.converters.BooleanDecimalConverter</converter-class>
</converter>
and at last we can add a converter attribute to af:selectBooleanRadio:
<af:selectBooleanRadio label="Label 1"
id="sbr1"
value="#{row.Isactual}"
group="Isactual"
converter="custom.BooleanDecimalConverter"
autoSubmit="true">
<af:clientListener type="click" method="onClickRadio"/>
<af:serverListener type="IsactualClickEvent"
method="#{viewScope.signerBean.onActual}"/>
</af:selectBooleanRadio>
What we have now:
A grid with rows, radio buttons show an "active" row and allow user to change "active" row immediately as he clicks the radio button.

How to highlight the current row when cell template button is clicked in angualar UI Grid

I have enabled ui-grid-selection on grid.As a result that when row is selected it will be get highlighted but my requirement is that i want to highlight the row only when the cell template button is clicked.Please let me know how to do this.
Code Sample
Finally was able to find a way to do that.Here is the answer.
What i did was,
In grid option changed enableRowSelection: false.
Add a function to cell template button.
Button Cell Template
<div><button class="btn btn-default" ng-click="grid.appScope.selectRow(row)">O</button></div>
Implement a function to select given row obj.
$scope.selectRow = function(row) {
row.setSelected(true);
};
if you want to unselect the selected row when the template button is clicked again you can use row.isSelectedthis will return boolean value.Here is the updated function code snippet.
$scope.selectRow = function(row) {
if(row.isSelected!=true){
//Select the row
row.setSelected(true)
}else{
row.setSelected(false)
}
};

selecting radio button by default in angularjs application

Please find the plunker for radio buttons. I am expecting when I select radio button, the selected object from $scope.itemList to be assigned to selectedItemDetails but it is not happening. And also by default when the page loads I want the default radio button to be selected based on var tagNumTobeSelectedByDefault = 2; i.e., "Gety of House" to be selected by default, how can I do it?
I am getting the index of the object to be selected from the list as follows:
var indexObjectTobeSet = $scope.itemList.map(function(x) {
return x.tagNum;
}).indexOf(tagNumTobeSelectedByDefault);
But failing to set that particular radio button.
You don't set the index, you set selectedItemDetails' value to the actual object you want selected in the $scope.itemList array. Thus,
$scope.selectedItemDetails = $scope.itemList.filter(function(item) { return item.tagNum === tagNumTobeSelectedByDefault; })[0];
should work (just remember to put it after the $scope.itemList definition). You might even want to consider moving the itemList object into a service or constant.
When you are declaring selectedItemDetails as an empty literal {}, you do not have a specific binding. Declare a property the ng-model can attach to :
$scope.selectedItemDetails = { selected : null }
and
<input type="radio" ng-model="selectedItemDetails.selected" name="eachCat" data-ng-value="eachCat">
Then it works. Now you can also set the default selected radio item with
$scope.selectedItemDetails = { selected : $scope.itemList[3] }
http://plnkr.co/edit/9hVxlhzvCmx3PIsbImVD?p=preview

How to programmatically clear a material design autocomplete in angularjs?

I have a material design autocomplete working correctly. Now I need to be able to clear the selected element when a button is clicked. I see that the element's delete button that appears on the right has an $mdAutocomplete.clear() call which is exactly what I need but I don't know how to launch that.
How can I capture the element and call the clear() method?
Thanks
Try to set the model which is binded to the search text with empty string:
self.clear = function() {
self.searchText = '';
}
See this codepen
self.clear = function() {
self.searchText = '';
}
eladcon answer works, but I would set md-min-length="1" to avoid let search box open.

want to enable a combobox only when another combo is selected in extjs

There are two combo boxes and a button.I want a validation i.e. if "combo1" is selected then "combo2" should get enabled and when i select "combo2" then browse button should get enabled.
Mabe something like that (insert text on first combobox):
The combobox2 and button must have this configs:
hidden:true,
disabled:true,
On combobox1:
listeners:{
change: function(combobox,newValue, eOpts){
var combo2 = Ext.ComponentQuery.query('#combo2ItemId')[0];
var button = Ext.ComponentQuery.query('#buttonItemId')[0];
if(!Ext.isEmpty(newValue)) {
combo2.setHidden(false).setDisabled(false);
button.setHidden(true).setDisabled(true);
}
else {
combo2.setHidden(true).setDisabled(true);
button.setHidden(true).setDisabled(true);
}
}
On combobox2:
listeners:{
change: function(combobox,newValue, eOpts){
var button = Ext.ComponentQuery.query('#buttonItemId')[0];
if(!Ext.isEmpty(newValue)) {
button.setHidden(false).setDisabled(false);
}
else {
button.setHidden(true).setDisabled(true);
}
}
I hope this helps!
I guess you may want to disable the second combo and button when the page first shows.
Then You could listen for the change event for each combo and in your handler code disable\enable which ever controls you need to based on the values passed into the handler function arguments.

Resources