How do you get Length of Text in a Mojo TextField? - webos

How do you get the length of the text inside a Mojo TextField?
I'm trying to set a multiLine TextField with a limit of 150 chars, I tried doing it with a counter, but ran into a issue of not being able to decrement the counter when the text was erased, or adding the right number when pasting text, so my new approach was to get the length of the text each time you press a letter.
I've already tried this: (gets called in the charsAllow attribute of the textField)
if (this.controller.get("mensaje").mojo.getValue().length <= 150) {
return true;
}
this.controller.get("mensaje").mojo.blur();
return false;
but it doesn't work.... I debugged and the function exits just after the line in bold... it doesn't even returns true or false.
I also tried assigning the length value to a variable or assigning the text to a variable and then get the length, but nothing.
It's the same issue. It returns just after the getValue().
Also, maybe because of this issue, the text scrolls instead of wrapping, but when the textField loses focus it wraps the text.

If 'mensaje' is the HTML id of your text field, try getting it and using .innerHTML().length. In other words, work with the DOM element using Javascript/Prototype functions instead of the Mojo object.

My first guess would be that "this" isn't being passed into charsAllow properly. Did you .bind(this) the function you're passing as an argument?

I found this a little odd... the function mojo.getValue() actually works... but not from inside the function called by "charsAllow"..., and also, the function called by charsAllow can't call any other function, it just breaks out of the function doing nothing... does someone have a way to limit the chars in a MultiLine TextField??? (mojo textfield, to preserve the look :D). Thanks!!

this blog explains a bit about text fields might be useful:
http://kmdarshan.com/wordpress/?p=3305

Related

Dynamically edited cell value in Handsontable is empty

I apologize if my question was already answered but I didn’t find any relevant answer.
I would like to dynamically edit cell value therefore I used:
var setButton = document.getElementById('setButton');
setButton.addEventListener('click', function(event) {
hot.getActiveEditor().beginEditing();
hot.render();
})
it edits cell but I don’t see original value, only empty.
Example:
https://jsfiddle.net/janzitniak/qdg420v8/6/
Note: Please select to any cell and then click to Set value to selected cell button.
Thank you for any help.
Solution
Long story short: Call enableFullEditMode() before you call beginEditing().
Not sure about the render() call though - I think that call can be removed.
JSFiddle
Storytime
I was looking for a solution to a similar problem, and had to look into the code to figure it out. In hindsight this was straightforward.
First there is some code which will reset the content of textareas to an empty string, to work with IME (or at least the comment says so)
And then there is code which will only set the original value into the cell, when the full editor mode is enabled.

Expect an element by xpath to have specific text

After pressing a save button a box will pop up and say if it was success or failed. The box has the same xpath no matter the result.
expect(element(by.xpath('path example')));
Inside the HTML for the element it says
<div class="panc lm-he" style="....."><span style="..."> Saved!</span></div>
edit -- oops it's early.
I want to know how can I have the expect come back true if the text "Saved!" is there or not. So if "Saved!" is present inside that element then it's true otherwise it's false.
Try with showing the output of the entire element like this:
element(by.xpath('path example')).then(function(element){
console.log(element);
});
not sure I understand want you want, but this way you will check if div with 'Saved!' text is Displayed
expect(element(by.xpath('.//div[text(), "Saved!"]')).isDisplayed).toBe(true);
As #Gunderson notes it doesn't matter what locator you use, the syntax will be the same. When I want to confirm text in an element I usually do something like this:
myElement.getText().then(function (text) {
expect(text).toContain(message)
});
That way you can tell by looking at the failure if the element didn't show up at all, or if it is visible but the text is not displayed, or if everything is fine and the test passes. So in your case it would just be
element(by.xpath('path example')).getText().then(function (text) {
expect(text).toContain('Saved!')
});

How to Auotmate Combo box for makemytrip as I am able to insert the value but once the focus is moved value is erased from the combobox

How to Auotmate Combo box for makemytrip as I am able to insert the value but once the focus is moved value is erased from the combobox
Try use Click first on that WebEdit (or maybe WebElement) object. Then, use SendKeys method to insert desired value. One potential issue here is that the value may still disappear even you use SendKeys, if so, try to send the string one by one. Google has lots of sample codes about SendKeys and sending string one character by one character.
If it's a WebEdit object, you might find it works best if you use the WebEdit("whateveritscalled").Type myDestinationString operation rather than Set or SendKeys.
Try the following, I am setting the values using the Elementid,it should work-
Browser("MakeMyTrip, India's No").Page("MakeMyTrip, India's No").Object.getElementById("from_typeahead1").value = "New Delhi, India (DEL)"
Browser("MakeMyTrip, India's No").Page("MakeMyTrip, India's No").Object.getElementById("to_typeahead1").value = "Mumbai, India (BOM)"

No action sent when NSSearchField is emptied?

I've set up an NSSearchField in a toolbar and connected an action in Interface Builder. This action gets called every time I enter some text, but not when I click the small cross to empty it or I somehow delete the text I just entered. Is this a bug or is it fixable?
Well, I figured out it actually works. My problem was that 1) I used the search string from the search field to filter some strings and searching a string for an empty string (#"") apparently returns no result 2) when I tried to log the search string using NSLog(#"%#",searchString) I got some output only with a non-empty string, while NSLog(#"sometexthere %#",searchString) seems to work!

WatiN and typing capital letters

I'm trying to automate a password entry but the website in question does not allow you to type your password with the caps lock key on. WatiN appears to use the caps lock key in order to type capital letters thus not allow this to work.
Does anyone know a workaround or a way to force WatiN to use the shift key?
You could write your own extension to the TextField class like this...
public static class WatinHelper
{
public static void TypeTextFast(this TextField textField, string text)
{
textField.SetAttributeValue("value", text);
}
}
and then use TypeTextFast instead of TypeText. This would furthermore improve typing speed considerably (particularly in IE) when running the WatiN test. See this for further details.
The TextField class has the Value property you can use to set text of the TextBox directly, without mimicking a manual input, like the TypeText() method.
As a side note, because the value is set behind the scene, it may not raise an event that the value has change, which could be necessary if action append as you type. The TypeText() was taking care of that for you. In those case you can use the Change() method after setting the Value.
It has been a while since I created anything with WatiN, but you can assign the text directly with something like this:
TextBox.Text = "PaSsWoRd";
I logged into a website without any problems using the above.

Resources