Search code examples
webospalm-premojo-sdk

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


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.


Solution

  • 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?