Error Style Class using Global onElementDataChange?

After watching the 2020.09 presentation, there was a demonstration of how to make it so that a textfield changes into it’s ‘error styleclass’ state, using onElementDataChange.

However, I’m not sure how to apply it to my project. In the demo, the code was something in a file called ‘baseCRUD.js’, however I have some questions related to that.

  1. Is this a singular global onElementDataChange for the whole project? So, I could just have one global onElementDataChange? (rather than having to do this for every single form)

And if 1 is true,
2. Where would this onElementDataChange go? In a form visible to all the other forms/modules, or in the Main Solution? baseCRUD in the demo was in ‘cloudSampleSolution/forms/baseCRUD.js’ , so that’s the Main Solution I’m pretty sure

CODE in Question

function onElementDataChange(oldValue, newValue, event){
	
	
	// CLEAR STYLE
	var elementName = event.getElementName();
	var field = elements[elementName];
	
	field.removeStyleClass('field-invalid');
	field.removeStyleClass('field-warning');
	field.toolTipText = null;
	
	// VALIDATE
	var markers = databaseManager.validate(
		foundset.getSelectedRecord(),
		{elementName : elementName});
	if(!markers){
		return;
	}
	
	// CHECK MARKERS / RENDER VALIDATION 
	if(markers.hasErrors){
		field.addStyleClass('field-invalid');
		field.toolTipText = markers.getMarkers(LOGGINGLEVEL.ERROR)[0].message;
	}
	// CHECK MARKERS / RENDER VALIDATION 
	var warnings = markers.getMarkers(LOGGINGLEVEL.WARNING);
	if(warnings.length){
		field.addStyleClass('field-warning');
		field.toolTipText = warnings[0].message;
	}
	
	return true;


}

Hi John,

In the webinar, the onElementDataChange was implemented in a base form which can be inherited into any form.
This was also demonstrated using the SvySample project which can be installed from the Servoy Package Manager. (I recommend that you use a completely blank workspace). Only the latest version v1.1.1 has the validation example, including the baseCRUD.js.

Best,
Sean