Error Style Class using Global onElementDataChange?

Forum to discuss the new web client version of Servoy.

Error Style Class using Global onElementDataChange?

Postby john1598360627 » Wed Feb 24, 2021 3:41 am

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

Code: Select all
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;


}
john1598360627
 
Posts: 169
Joined: Tue Aug 25, 2020 3:03 pm

Re: Error Style Class using Global onElementDataChange?

Postby sean » Fri Feb 26, 2021 9:21 pm

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
Software Engineer
Servoy USA
sean
 
Posts: 370
Joined: Mon May 21, 2007 6:26 pm
Location: USA


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 12 guests