I want to do the same in app maker https://codepen.io/Seba951/pen/siapk
I was advancing this.
function caracteres(){
var cadena = app.pages.Archivos.descendants.txtCaracteres.value;
var x = cadena.length;
console.log(x);
return x;
}
onAttach: widget.getElement().addEventListener('keypress', caracteres);
Just as an example do the following:
For the label onDataLoad event set the following custom script:
var elem = widget.parent.children.Field1;
var value = elem.value;
if (value !== null) {
widget.text = (elem.maxLength - value.length).toString();
} else {
widget.text = elem.maxLength.toString();
}
For the textbox or textarea widget set the following onInputChange event script:
var elem = widget.value;
if (elem !== null) {
var length = elem.length;
widget.parent.children.Label6.text = (widget.maxLength - length).toString();
} else {
widget.parent.children.Label6.text = widget.maxLength.toString();
}
That would get the same thing accomplished.
Alternatively follow steps 1-4 and then create the following function in your client script:
function caracteres(widget1, widget2) {
var cadena = widget1.value;
if (cadena !== null) {
var x = cadena.length;
console.log(x);
widget2.text = (widget1.maxLength - x).toString();
} else {
widget2.text = widget1.maxLength.toString();
}
}
And in your textbox or textarea widget onDataLoad and onInputChange events include the following:
caracteres(widget, widget.parent.children.Label6);
This way you can reuse the same function for multiple textboxes or textareas throughout your application.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.