How to limit the textarea size - smartclient

I need to limit the textarea to 4 characters...
my current javascript
{
name : "pin",
title : "PIN",
align:"center",
textArea:"isc.TextArea.setCharacterWidth(4)"
}
Can anyone tell me how can I do that please?

You can use following methods both on TextAreaItem and TextItem:
text.setEnforceLength(true);
text.setLength(4);

You can use TextAreaItem field of smartgwt to create multi-line text area.
To restrict the number of characters for this field, setLength can be used.
For example:
private TextAreaItem text = new TextAreaItem("pin", "PIN");
text.setLength(4);
text.setAlign(Alignment.CENTER);

Related

Get the caret position for Blazor text input

I am working on a Blazor textarea input. What I want to achieve is whenever user types "#" character, I am going to popup a small window and they can select something from it. Whatever they select, I will insert that text into the textarea, right after where they typed the "#".
I got this HTML:
<textarea rows="10" class="form-control" id="CSTemplate" #bind="original" #oninput="(e => InputHandler(e.Value))" #onkeypress="#(e => KeyWasPressed(e))"></textarea>
And the codes are:
protected void InputHandler(object value)
{
original = value.ToString();
}
private void KeyWasPressed(KeyboardEventArgs args)
{
if (args.Key == "#")
{
showVariables = true;
}
}
protected void AddVariable(string v)
{
original += v + " ";
showVariables = false;
}
This worked very well. The showVariables boolean is how I control the pop-up window and AddVariable function is how I add the selected text back to the textarea.
However, there is one small problem. If I've already typed certain text and then I go back to any previous position and typed "#", menu will still pop-up no problem, but when user selects the text and the insert is of course only appended to the end of the text. I am having trouble trying to get the exact caret position of when the "#" was so I only append the text right after the "#", not to the end of the input.
Thanks a lot!
I did fast demo app, check it https://github.com/Lupusa87/BlazorDisplayMenuAtCaret
I got it - I was able to use JSInterop to obtain the cursor position $('#CSTemplate').prop("selectionStart") and save the value in a variable. Then use this value later in the AddVariable function.
you can set your condition in InputHandler and when you are checking for the # to see if it's inputed you can also get the length to see that if it's just an # or it has some characters before or after it obviously when the length is 1 and value is # it means there is just an # and if length is more than one then ...

How to write XPath based on elements in Chrome Dev Tools?

I am trying to get XPaths for underlined values in the image below. I have a list of cards which is always different, and I need to grab values from the inside of the highlighted card which has 'highlight' in its class.
When I grab the XPath through inspecting an element in Chrome, I get something like this //*[#id="rental-asset"]/div/div[1]/div/rdo-nav-card-asset[11]/div/div[1]/div/i which doesn't work for me since that 11 in brackets is always going to be a different value. How can I create an XPath for these elements based on their unique class?
Here is how to get the first underlined thing. I think you should be able to take it from here.
//rdo-nav-card-asset/div[contains(#class,'panel') and contains(#class,'highlight')]/div[contains(#class,'panel-heading')]/div[contains(#class,'panel-title')]
You can Split the xpath and iterate in the range they are expected to occur.
Suppose they have that value from 1-22 you can something like this.
This is a python code.
str1 = '//*[#id="rental-asset"]/div/div[1]/div/rdo-nav-card-asset['
str2 = ']/div/div[1]/div/i'
for i in range(1, 22):
str3 = str1 + str(i) + str2
a = driver.find_element_by_xpath(str3).text
print a
You can grab the other elements or data inside the loop.
Comment below if you have any confusion.
You can firstly find the highlight card and use it as the search context of those underline texts.
Code as following:
var activeCard = driver.findElement(By.css('rdo-nav-card-asset > div.rdo-card-highlight'));
// the text of 1rd underline
var title = activeCard.findElement(By.css('.panel-title')).getText();
// the text of 2rd underline
var title = activeCard.findElement(By.xpath('.//div[#class='rdo-card-metric'][1]'))
.getText();
// the text of 3rd underline
var title = activeCard.findElement(By.css('.text-danger')).getText();
// the text of 4rd underline
var title = activeCard.findElement(By.xpath('.//div[#class='rdo-card-metric'][3]'))
.getText();

How to Read text filled in a Text Box

Here I am Providing u the Text Box Image with its X-path
and Here is the Code for it, that I had tried:
{
String NameTxtBxData = driver.findelement(By.id("ngoName")).gettext();
System.out.println(NameTxtBxData);
}
The element with id "ngoName" is an input. The text from an input is defined in the value property/attribute:
String NameTxtBxData = driver.findElement(By.id("ngoName")).getAttribute("value");
Hi to read a value form a text filed or any input filed there is a hidden attribute value which keeps the value entered by you inside it hence to read the value in the text box simply do it like below
String NameTxtBxData = driver.findelement(By.id("ngoName")).getAttribute("value");
System.out.println(NameTxtBxData);
Hope this helps you

Create new paragraph with Docx4j

I'm having problem creating a Paragraph with docx4j. Well, actually not the paragraph itself, but it's contents. I'm putting together a new document from paragraphs (actually "blocks" made of paragraphs) and everything is working fine. I'm appending them to a list, and when all needed paragraphs are there, I assemble the document. Now, between these blocks, I need new paragraphs, with custom text added. I'm using this function to create the paragraph:
private P createParagraph(String content) {
P result = factory.createP();
R run = factory.createR();
Text text = factory.createText();
text.setValue(content);
run.getContent().add(text);
result.getContent().add(run);
System.out.println("HEADER : " + result.toString());
return result;
}
The print only prints "HEADER : ", the result.toString() is an empty string. Why is that?
BONUS question : I did not want to open a new thread for this. Is it possible, to add an id for a paragraph, which will appear in the generated html? (like p id="xyz" ...>
Thank you very much!
If you want to see the XML your P object will become, use:
System.out.println(
XmlUtils.marshaltoString(result, true, true) );
org.docx4j.wml.P is a class generated by JAXB's xjc.
There are a couple of plugins listed at https://java.net/projects/jaxb2-commons/pages/Home which we could have used to generate a toString method, but we didn't.
If you want the text content of the paragraph, you can use TextUtils

Initialize the textfields in Sencha touch 2

I have a sencha touch form, which has two textfields. I want to assign some text to them on page load. I tried setting values in init and launch functions. But in those function textfield are not available, they are undefined. So which event should be used for this purpose?
Either set the values with the setRecord({textFieldName1: "value", textFieldName2: "value"}) method of the container, or assign an id to the text fields and access them via Ext.getCmp('textFieldName').setValue("value") in the initializemethod of the container.
Can't you use the value property directly ? Setting the value will make the textfield fill with the corresponding value of value property i.e in our case, "Sample Text 1" etc ..
e.g
{
xtype:'textfield,
value:'Sample Text 1 ',
},
{
xtype:'textfield,
value:'Sample Text 2 ',
}