I have added a Textbox in a program called M3 ARS110. With a width of 30.
But I want to restrict the user from entering more than 20 characters. After length 20 cursor should not go ahead.
I want to set max length for the user can enter.
Can somebody help me with the request. I did not succeed so I tried to throw a error message but that also did not work.
Below is my Typescript.
/**
* H5 Script SDK sample.
*/
/**
* Adds label, textbox, combobox, checkbox, and button elements
* On button click, toggles the checkbox and prints the textbox and combobox values on the console
*/
class Textbox {
private controller: IInstanceController;
private log: IScriptLog;
private args: string;
private charlength:any="";
private data:any="";
private contentElement: IContentElement;
constructor(scriptArgs: IScriptArgs) {
this.controller = scriptArgs.controller;
this.log = scriptArgs.log;
this.args = scriptArgs.args;
}
public static Init(args: IScriptArgs): void {
new Textbox(args).run();
}
private run(): void {
this.contentElement = this.controller.GetContentElement();
console.log("testconsole")
this.addLabel();
this.addTextBox();
this.addEventListener();
}
private addLabel(): void {
const labelElement = new LabelElement();
labelElement.Name = "testLabel";
labelElement.Value = "Batch Number";
labelElement.Position = new PositionElement();
labelElement.Position.Top = 3;
labelElement.Position.Left = 45;
this.contentElement.AddElement(labelElement);
}
private addTextBox(): void {
const textElement = new TextBoxElement();
textElement.Name = "testTextBox";
textElement.Value = "";
textElement.Position = new PositionElement();
textElement.Position.Top = 3;
textElement.Position.Left = 55;
textElement.Position.Width = 20;
this.contentElement.AddElement(textElement);
this.data = textElement.Value.split(" ");
this.charlength = this.data.length(20);
}
private addEventListener(): void{
if (this.charlength > 20){
this.controller.ShowMessageInStatusBar("Length is more");
}
}
}