cancel
Showing results for 
Search instead for 
Did you mean: 

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

dhanikawick41
Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

ashishjain14
Employee
Employee

This seems to be a bug, if you try following sequence which means 12345, then 6, then 7 and so on it works. But the moment you have 12345, then 6, then 6 it fails the second time. We will report this to the dev team.

dhanikawick41
Participant
0 Kudos

Thank you ashishjain14 for your reply. Yes, what you said seems to be correct.

Answers (1)

Answers (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert

When you call setValue to put the trimmed value back into the field you can also specify a second (optional) parameter to indicate if the setValue should notify the control that the value changed. This allows you to set a value from a rule where you don't want OnValueChanged to trigger.

context.setValue(trimmedValue, false);
dhanikawick41
Participant
0 Kudos

Thank you bill.froelich. I was able to stop the event triggering from the code by adding the false parameter.