SAPUI5: sap.m.TextArea cursor position - cursor

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

Related

How can I add text to a Checkbox I create using iTextSharp?

Derived from Jeff S's methodology found here, I can add a "Checkbox" to a PDF page like so:
PdfPTable tblFirstRow = new PdfPTable(5);
tblFirstRow.SpacingBefore = 4f;
tblFirstRow.HorizontalAlignment = Element.ALIGN_LEFT;
. . . // code where textboxes are added has been elided for brevity
PdfPCell cell204Submitted = new PdfPCell()
{
CellEvent = new DynamicCheckbox("checkbox204Submitted", "204 Submitted or on file")
};
tblFirstRow.AddCell(cell204Submitted);
doc.Add(tblFirstRow);
The DynamicCheckbox class, based on Jeff S's CustomCellLayout class, is:
public class DynamicCheckbox : IPdfPCellEvent
{
private string fieldname;
private string cap;
public DynamicCheckbox(string name, String caption)
{
fieldname = name;
cap = caption;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
RadioCheckField ckbx = new RadioCheckField(writer, rectangle, fieldname, "Yes");
ckbx.CheckType = RadioCheckField.TYPE_CHECK;
ckbx.Text = cap;
PdfFormField field = ckbx.CheckField;
writer.AddAnnotation(field);
}
}
My problem is that the checkbox's text (the string assigned to ckbx.Text) is not displaying. The checkbox (outsized) occupies the last cell in the table row, but there is no (visible) accompanying text.
What's missing from my code?
Note: I tried to reduce the size of the checkbox by doing this:
Rectangle tangle = new Rectangle(20, 20);
//RadioCheckField ckbx = new RadioCheckField(writer, rectangle, fieldname, "Yes");
RadioCheckField ckbx = new RadioCheckField(writer, tangle, fieldname, "Yes");
...but that attempt failed - with that code, I can't even "find" the checkbox in the generated PDF file - clicking willy-nilly in column 5 conjures up no checkbox...
Others have answered the label part. The Rectangle that you have called "tangle" needs to be calculated off of the rectangle that comes into the event handler, similar to
Rectangle tangle = new Rectangle(
rectangle.Left,
rectangle.Top - PDFStyle.boxsize - 4.5f,
rectangle.Left + PDFStyle.boxsize,
rectangle.Top - 4.5f
);
Where PDFStyle.boxsize is the width/height of the checkbox and 4.5f is the padding the edge of the cell. Basically the rectangle isn't relative to the cell, but absolute to the page.
As described in ISO-32000-1, a check box is a field of type Button. If you define text for a button, you want to define the text that is displayed on the button. However: in the case of a check box, there is no such text! Instead, you have two appearances, one for the Off value and one for the Yes value.
An educated guess made by an attentive reader would be that you don't want to add text (to the button), but that you want to add a label (for a checkbox). Again you should consult ISO-32000-1 and you'll discover that the spec doesn't say anything about labels for check boxes. The concept just doesn't exist at the level of an AcroForm.
This doesn't mean the concept doesn't exist in general. Many PDF tools allow you to define check boxes that are preceded by a label. When you look inside the PDF, you'll discover that this label is just part of the content, whereas the check box is represented by a widget orientation.
Let's take a look at the official documentation instead of frustrating ourselves searching on every place of the web except on the official web site. More specifically: let's take a look at the Buttons example from Chapter 7 of my book. You'll see that one can set text for a real button:
PushbuttonField button = new PushbuttonField(writer, rect, "Buttons");
button.setText("Push me");
This isn't possible with check boxes (for the obvious reason that the appearance of a check box is completely different). If we want to add a label, we can add it for instance like this:
checkbox = new RadioCheckField(writer, rect, LANGUAGES[i], "Yes");
field = checkbox.getCheckField();
field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", onOff[0]);
field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Yes", onOff[1]);
writer.addAnnotation(field);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
new Phrase(LANGUAGES[i], font), 210, 790 - i * 40, 0);
You can find the C# version of these examples here: http://tinyurl.com/itextsharpIIA2C07
Creating a checkbox, and then accompanying text to its right, can be done like this:
PdfPCell cell204Submitted = new PdfPCell()
{
CellEvent = new DynamicCheckbox("checkbox204Submitted")
};
tblFirstRow.AddCell(cell204Submitted);
// . . . Chunks and an anchor created; that code has been elided for brevity
Paragraph parCkbxText = new Paragraph();
parCkbxText.Add(Chunk204SubmittedPreamble);
parCkbxText.Add(ChunkBoldNote);
parCkbxText.Add(Chunk204Midsection);
parCkbxText.Add(anchorPayeeSetup204);
PdfPCell cellCkbxText = new PdfPCell(parCkbxText);
cellCkbxText.BorderWidth = PdfPCell.NO_BORDER;
tblFirstRow.AddCell(cellCkbxText);
public class DynamicCheckbox : IPdfPCellEvent
{
private string fieldname;
public DynamicCheckbox(string name)
{
fieldname = name;
}
public void CellLayout(PdfPCell cell, Rectangle rectangle, PdfContentByte[] canvases)
{
PdfWriter writer = canvases[0].PdfWriter;
RadioCheckField ckbx = new RadioCheckField(writer, rectangle, fieldname, "Yes");
ckbx.CheckType = RadioCheckField.TYPE_CHECK;
ckbx.BackgroundColor = BaseColor.ORANGE;
ckbx.FontSize = 6;
ckbx.TextColor = BaseColor.WHITE;
PdfFormField field = ckbx.CheckField;
writer.AddAnnotation(field);
}
}

selectionchanged event is not working

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();
}
}

How to get value of cell at current row GridView winforms devexpress

I need to know which row I selected and get value of cell(Ex:idproduct) before to click Edit button.
As #brendon is referring to, if gridView is the current View on your GridControl:
// Get your currently selected grid row
var rowHandle = gridView.FocusedRowHandle;
// Get the value for the given column - convert to the type you're expecting
var obj = gridView.GetRowCellValue(rowHandle, "FieldName");
You can use the GridView's GetRowCellValue method to retrieve the focused row value.
http://documentation.devexpress.com/#windowsforms/DevExpressXtraGridViewsGridGridView_GetRowCellValuetopic
See also: http://documentation.devexpress.com/windowsforms/CustomDocument753.aspx
public int idproductx;
public void tProductGridView_RowClick(object sender, RowClickEventArgs e)
{
if (e.Clicks > 0)
{
idproductx = (int)((GridView)sender).GetRowCellValue(e.RowHandle, "idproduct ");
}
}

How to add items from a textbox to an array? C#

I want to add items from 13 textboxes to the 13 elements of an array. All at one time using a button. How would I go about that?
List<double> scoreArray = new List<double>();
TextBox[] textBoxes = { week1Box, week2Box, week3Box, week4Box, week5Box, week6Box, week7Box, week8Box, week9Box, week10Box, week11Box, week12Box, week13Box };
for (int i = 0; i < textBoxes.Length; i++)
{
scoreArray.Add(Convert.ToDouble(textBoxes[i].Text));
}
Put an event handler on the button's Click event.
In the handler, extract the textbox values and set them into the values of the array.
Easy peasy!

Prevent double click on a row divider triggering celldoubleclick event

In a datagridview with rowheaders visibility set to false and allowusertoresizerow set to true, i need to prevent the celldoubleclick event to trigger if doubleclicked on the rowdivider (Toublearrow of the row resize is visible when the cursor is on the divider).
Thanks
I guess the easiest way would be checking the clicked area of the grid on the CellDoubleClick event itself; the logic would be to return in case rowresizetop or rowresizebottom areas are clicked and continue processing if not. Please check an example below for more details:
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
// get mouse coordinates
Point mousePoint = dataGridView1.PointToClient(Cursor.Position);
DataGridView.HitTestInfo hitTestInfo = dataGridView1.HitTest(mousePoint.X, mousePoint.Y);
// need to use reflection here to get access to the typeInternal field value which is declared as internal
FieldInfo fieldInfo = hitTestInfo.GetType().GetField("typeInternal",
BindingFlags.Instance | BindingFlags.NonPublic);
string value = fieldInfo.GetValue(hitTestInfo).ToString();
if (value.Equals("RowResizeTop") || value.Equals("RowResizeBottom"))
{
// one of resize areas is double clicked; stop processing here
return;
}
else
{
// continue normal processing of the cell double click event
}
}
hope this helps, regards

Resources