Input suggestions

You might have seen errors with suggestions in the platform. Did you know that you could use this same system in your own app?

Click to see example in action

validated

Good to know

  • there are two type of suggestions:
    • blocking (if you send an error)
    • non-blocking (if you send a warning)
  • this system was initially developed to help designer respect good syntax conventions
  • it is not limited to syntax conventions, you can use Message.formatSuggestion for all kind of validations

How to implement it

postValidate way

  • works with any type of field

Example: suggest accent and begining / trailing spaces removal

package com.simplicite.objects.Demo;

import java.util.*;
import com.simplicite.util.*;
import com.simplicite.util.tools.*;
import org.apache.commons.lang3.StringUtils;

/**
 * Business object DemoSupplier
 */
public class DemoSupplier extends ObjectDB {
	private static final long serialVersionUID = 1L;
	
	@Override
	public List<String> postValidate() {
		List<String> msgs = new ArrayList<>();
		
		String str = getFieldValue("demoSupValidatedText");
		String cleaned = StringUtils.stripAccents(StringUtils.strip(str));
		
		if(!str.equals(cleaned))
			msgs.add(Message.formatSuggestion("MY_WARNING_CODE", null, Message.WARN, "demoSupValidatedText", cleaned));
			
		return msgs;
	}
}

“Validated Text” way (NOT RECOMMENDED)

Summary

Be carefull while using this feature: due to limitations on the functionnality, the field validation will evolve in the near future.

  • You must have created a FieldType ( Administration > Field Type ) with the name of a method to call to execute the validation :

  • The field you’re working on must be of type “Validated Text”
  • You must create a “Field Type” and select this type in the “Field Validation” selector on the field Form

  • Finally create the method on the object
public String camelCaseSuggest(String val){
	return SyntaxTool.getWarningMessage(getField("demoSupValidatedText"), SyntaxTool.CAMEL, null);
}

Limitations:
- in the method, you only get the value, not the name of the field to validate
- the method must be implemented on every object that uses the validation
- technique limited to the validated text input types

2 Likes