Skip to Content
0
Jul 14, 2020 at 06:40 AM

SAP MDK problem limiting the number of characters in Simple Property OnValueChange event

91 Views

Hi Experts,

I have a requirement where the input should not be more than 5 characters in a Simple Property control.

In the OnValueChange event I have added a rule with the code below.

var context;
export default function InspectionShortTextValidation(context) {
	// Making the inspection short text not to exceed 5 characters
	var inspectionShortTextValue = context.getValue();
	var maxLength = 5;
	if (inspectionShortTextValue.length > 5) {
		var trimmedValue = inspectionShortTextValue.substring(0, maxLength);
		context.setValue(trimmedValue);
	}
}

Although it works, there seems to be a scenario where the event does not get triggered.

For an example when I type in '123456', it triggers the event and changes the string correctly to '12345', which causes the event to trigger again as the value was changed from the code although it is not a user input. But when I try to add '6' again, the event does not get triggered for some reason and it keeps '123456' as a valid input. I need to do another change in order to trigger the event.

How can I avoid this please. Is the way I am doing it wrong? or is there a way I can identify if the change was causeed from a user input or from a code?

Thank you.