selectionchanged event is not working - extjs

I have two felds in my dialog, one is text field(leftpadding) and another is dropdown with four options(option 1, option 2, option 3, option 4).My requirement is to display/enable the textfiled when the user selects option 3 and option 4 only.
I added listeners(selectionchanged) node to the dropdown field. loadcontent event is firing but selectionchanged is not working fine. Please find below for the code snippet
selectionchanged:
function(field,value){
var layoutoption = "";
layoutoption = field.findParentByType('dialog').form.findField('./footerstyle').getValue();
alert('layoutoption :'+layoutoption);
if(layoutoption =='3' || layoutoption =='4'){
field.findParentByType('dialog').form.findField('./leftPadding').enable(this);
}else {
field.findParentByType('dialog').form.findField('./leftPadding').disable(this);
}}

If you look at the CQ.form.Selection API, you would find that when the selectionchanged event is fired, the following arguments would be passed to the listener.
this : The selection field
value : The raw value of the selected field
isChecked : true / false, used when the selection is of type checkbox.
Thus, you could modify your listener as shown below.
function(field, value) {
var dlg = field.findParentByType('dialog');
// the value holds the value of the selection
if(value =='3' || value =='4'){
// getField() of the dialog class returns the field with the given name
dlg.getField('./leftPadding').show();
}else {
dlg.getField('./leftPadding').hide();
}
}
The getField() method of the CQ.Dialog returns the field with the given name. In case more than one field with the same name exists, it returns an array of those fields. You can then show() or hide() the fields based on your requirements.
EDIT :
CQ 5.4 somehow doesn't remove the entire widget, instead removes only the input field leaving behind the Field Label, Description etc.
In such cases the following function may be used.
function(field, value) {
var dlg = field.findParentByType('dialog');
if(value == '3' || value == '4') {
dlg.getField('./leftPadding').el.parent('.x-form-item').show();
}
else {
dlg.getField('./leftPadding').el.parent('.x-form-item').hide();
}
}

Related

Finding the wrong UIElement in Grid

Problem: When I select a check box (in Column '1'), the OnSelection event should find a Label on Column '0' in the same Row, but I am getting:
System.InvalidCastException: 'Unable to cast object of type 'System.Windows.Controls.CheckBox' to type 'System.Windows.Controls.Label'.'
I am initializing the view as such:
Label lbName = new() { Content = "labelName" };
Grid.SetColumn(lbName, 0);
GrWindow.Children.Add(lbName);
CheckBox ckSelection = new();
ckSelection.Checked += OnSelection;
Grid.SetColumn(ckSelection, 1);
GrWindow.Children.Add(ckSelection);
And on the OnSelection method, where the exception is triggered:
string? labelName = GrWindow.Children.
Cast<Label>().
First(e => Grid.GetRow(e) == row && Grid.GetColumn(e) == 0).
Content as string;
In other place in my app, I am using a very similar approach to get a name from Row '0' and works fine.
There is only one children on every row/column = '0', and its a label, I dont know how to debug such situations, since the checkbox is on column='1'.
Thanks in advance.
Replace
.Cast<Label>()
with
.OfType<Label>()
to get only the Labels.
Otherwise you are trying to cast all child elements to Label, which will of course fail for the CheckBox.
An alternative to querying the Children collection might be to assign the associated Label to the Tag property of the CheckBox
ckSelection.Tag = lblName;
and get it back in the event handler by
var checkBox = (CheckBox)sender;
val label = (Label)checkBox.Tag;

SAPUI5: sap.m.TextArea cursor position

I'm using sap.m.TabContainer with items containing sap.m.TextArea's. If I switch between tabs,
the cursor position in the textarea's is reseted. I would like to keep the cursor position in the textarea's. Is there a possibility to store the current cursor position bevor leave and set the stored position on enter of the textarea?
Regards, Annie
sap.m.TextArea inherits from the sap.m.InputBase which provides focus related APIs e.g. getFocusInfo and applyFocusInfo.
To get notified when the user enters or leaves the textarea you can add onfocusin and onfocusout as an event delegate and then store the focus info on focusout and apply the stored focus info on focusin. E.g.:
var oFocusDelegate = {
mFocusInfo: {},
onfocusin: function(oEvent) {
var oTextArea = oEvent.srcControl;
var mFocusInfo = this.mFocusInfo[oTextArea];
if (mFocusInfo) {
oTextArea.applyFocusInfo(mFocusInfo);
}
},
onfocusout: function(oEvent) {
var oTextArea = oEvent.srcControl;
this.mFocusInfo[oTextArea] = oTextArea.getFocusInfo();
}
};
// add focus delegate to textareas
// TextArea required from "sap/m/TextArea"
new TextArea().addEventDelegate(oFocusDelegate);
Please see: https://jsbin.com/wusejifili/1/edit?html,output

Default value gets stored in another column based on value selected from LOV

Table-Items
Columns-Order_Type
(Sales,
Return,
Defective)
Order_Type_Id(1,2,3)
i.e 1-Sales,
2-Return,
3-Defective
VO has Transient attribute-OrderType which has an LOV showing Order_Type.
Based on selected Order_Type, Order_Type_Id should get stored in Order_Type_Id column
public Number getOrder_Type_Id() {
String orderType = null;
Number orderNumber = null;
if (getOrderType() != null) {
orderType = getOrderType();
if (orderType.equals("Sales")) {
orderNumber = new oracle.jbo.domain.Number(2);
} else if (orderType.equals("Return")) {
orderNumber = new oracle.jbo.domain.Number(3);
} else if (orderType.equals("Defective")) {
orderNumber = new oracle.jbo.domain.Number(4);
}
this.setOrder_Type_Id(orderNumber);
}
Following code worked.
Writing following code in Order_Type_Id:
public Number Order_Type_Id()
{
String orderType=null;
Number orderNumber=null;
if(getOrder_Type()!=null){
orderType=getOrder_Type();
if(orderType.equals("Sales")){
orderNumber=new oracle.jbo.domain.Number(2);
}
else if(orderType.equals("Defective")){
orderNumber=new oracle.jbo.domain.Number(3);
return orderNumber;
}
else
{
return (Number)getAttributeInternal(Order_Type_Id);}
}
}
In Order_Type_Id attribute add dependency or Order_Type
Assuming LOV VO is also from Query not from static list :
It is developed in ADF 11g
OrderTypeLOVVO :
order_type_id - back-end stored column
order_type_desc - display column
BaseOrderVO
OrderTypeId - transient attribute - LOV - OrderTypeLOVVO
OrderTypeDesc - transient attribute - OutputText column with default value - 1
orderTypeId
- Make autoSubmit property true in both places in VO and in jsff page ( drop it as select one choice) .
- OrderTypeId value will be bindings.orderTypeId.inputValue
- Shuffle the dependent attribute Order_type_desc from left to right in dependecies component of VO.
OrderTypeDesc
Make default value as 1 and in jsff page set partial trigger dependent of orderTypeId after dropping it as output label.
Make OrderTypeDesc value attribute as bindings.orderTypeId.attributeValue
We need to make OrderTypeDesc value as orderTypeId.attributeValue because when you select OrderTypeId as sales (this is inputValue), so backend value (id) is 1. so attributeValue will get the id of the selected value in LOV.
Same works with static list VO too.
As per your requirement, In programatically,
I have created a method on value change listener of LOV,
changeValue() is the method in bean class.
public void changeValue(ValueChangeEvent valueChangeEvent) {
AppModuleImpl module = getApp(); // creating appModuleImpl class object
//definition for getApp() is given below.
item_desc = module.assignValue(valueChangeEvent.getNewValue().toString());
// This item_desc value is declared globally.
//assignValue method of AppModuleClass is given below
bind_item_desc.setValue(item_desc);
AdfFacesContext adfFacesContext = AdfFacesContext.getCurrentInstance();
adfFacesContext.addPartialTarget(bind_item_desc);
// bind_item_desc is the binding attribute of output label which needs to be refreshed.
// Add event code here...
}
public static AppModuleImpl getApp() {
return (AppModuleImpl)Configuration.
createRootApplicationModule(
"Model.AppModule", // where your module is stored
"AppModuleShared"); // chosen configuration
}
Here Model.AppModule is the location of AppModule.
assingValue() of AppModuleClass where it will assign the value according to the selected value in LOV.
public String assignValue(String value)
{
String item_desc=null;
System.out.println("Changed value " + value);
if(value.equals("Sales"))
{
item_desc="14";
}
return item_desc;
}
In assignValue, Parameter is value which will be input from bean class (a selected value from LOV) and returning the String parameter which you will be needed back again in bean class.
So when you select a value in LOV, it will trigger the value change listener method (changeValue()) and will navigate to AppModule . In AppModule , value will be assigned and come back to Bean class.
But it will not reflect untill, you will not refresh the page component.
<af:selectOneChoice value="#{bindings.item_id_lov.inputValue}"
label="item for lov"
required="#{bindings.item_id_lov.hints.mandatory}"
shortDesc="#{bindings.item_id_lov.hints.tooltip}"
id="soc4" autoSubmit="true"
valueChangeListener="#{bean1.changeValue}">
<f:selectItems value="#{bindings.item_id_lov.items}" id="si4"/>
</af:selectOneChoice>
Here value change listener is called in SelectOneChoice and autoSubmit is true.
<af:panelLabelAndMessage label="item description"
id="plam1" partialTriggers="soc4">
<af:outputFormatted value="#{bean1.item_desc}" binding="#{bean1.bind_item_desc}"
id="of1"/>
</af:panelLabelAndMessage>
Here , in value attribute item_desc is assigned (which is declared in bean). Also binding got created for the output label. PartialTrigger is assigned of LOV as outputLabel is dependent on LOV.

XPages get Value selected from combo box

I want to display the selected value from the comboBox into a label.
<xp:label id="label4">
<xp:this.value><![CDATA[#{javascript:var componenta = Contr.getItemValueString("txt_tipcontractcv");
if (componenta == "")
{ return "void";}
if (componenta !="")
{ return "My value is "+componenta}}]]></xp:this.value>
</xp:label>
The label is on a panel, and I did a partial refresh to the respective panel.
My comboBox is binded to a data element.
label4 is always void. Why?
Thank you,
Florin
I changed code into:
var componenta = getComponent("combo").getValue();
if ((componenta == null) || (null == componenta))
{ return "void";}
else if ((componenta != null) || (null != componenta))
{ return "My value is "+componenta}
and now it returns : My value is
It seems that componenta is an empty string. Why?
Try Contr.getValue("txt_tipcontractcv") (assuming that Contr is your datasource).
The reason is the value selected is not sent to the server.
Could you give us the code for combobox, and panel with label. It will give us clear idea for the cause
Are you using partial execution mode?
Is combo box bind to data source value="Contr.txt_tipcontractcv"?
You may also code the label as below, if that suits
<xp:label id="label4" value="Contr.txt_tipcontractcv" />

object not set to instance of an object!! ComboBox SelectedIndex SelectedItem

I am developing a program which gets all Clearcase regions (basically strings) & adds them to Combo box. I compare an existing clearcase region string in newly added items in combo box & if it is found then I want to select it, but because nothing is selected for the first time, selectedItem is null & selectedIndex = -1.
when I assign 0 to selectedIndex, error comes --> object not set to instance of an object!! same problem when you assign something to selectedItem; gives an error.
whats wrong with my code?
private void PopulateClearCaseRegionComboBox ( )
{
clearCaseRegionComboBox.Items.Clear();
foreach ( Match token in RegularExpression.Match( "\\w+", clearTool.CmdExec( "lsregion" ) ) )
{
clearCaseRegionComboBox.Items.Add(token.Value.Trim());
if (clearCaseRegion.ToUpperInvariant() == token.Value.Trim().ToUpperInvariant())
{
clearCaseRegionComboBox.SelectedIndex = clearCaseRegionComboBox.Items.IndexOf(token.Value.Trim());
}
}
clearCaseRegionComboBox.Sorted = true;
}
A notification: the SelectedIndexChanged event also occurs when you set SelectedIndex or SelectedItem. So if you have something there, check it out also. :) I've passed several hours on it, because you don't see it while debugging.
Are you sure the following line returns a valid index?
clearCaseRegionComboBox.Items.IndexOf(token.Value.Trim());
The Add method returns the index of the newly added item. You can use that value inside your if statement.
private void PopulateClearCaseRegionComboBox ( )
{
clearCaseRegionComboBox.Items.Clear();
foreach ( Match token in RegularExpression.Match( "\\w+", clearTool.CmdExec( "lsregion" ) ) )
{
int index = clearCaseRegionComboBox.Items.Add(token.Value.Trim());
if (clearCaseRegion.ToUpperInvariant() == token.Value.Trim().ToUpperInvariant())
{
clearCaseRegionComboBox.SelectedIndex = index;
}
}
clearCaseRegionComboBox.Sorted = true;
}
Perhaps you can reveal more of your code in context? I say this because it would seem impossible to get this error at this point in your representative code. You've already used the object to add an item 3 lines up.
Are you sinked to any events on the combo box that would assign the clearCaseRegionComboBox variable to null?

Resources