Select to view content in your preferred language

Editor widget - validations

117
3
Sunday
MKY
by
Occasional Contributor

Editing attributes in Editor widget needs an event before applying edit. I have columns that their values depend on another column. I tried Form Constraints and Field calculations in Arcade but they do not work for all scenarios. 

If there is a new event like "before-apply-edit", it will help in validating all columns before posting.

Regars,

Markos

 

Tags (1)
0 Kudos
3 Replies
VenkataKondepati
New Contributor

Hi Markos,

Totally agree — a before-apply-edit event would be super useful for validating or adjusting values before the Editor widget submits the edits.

I’ve run into the same issue when one field depends on another. Arcade constraints and calculations are great for some use cases, but they don’t always work when the logic gets more complex.

If you’re using Developer Edition, a workaround is to hook into the form submit logic manually, validate the fields, then call applyEdits() yourself. But yeah, having a native event like before-apply-edit would make things much cleaner.

Might be worth submitting this as an enhancement request to Esri — I know others would benefit too.

Cheers,
Venkat

0 Kudos
JeffreyThompson2
MVP Frequent Contributor

I was looking for a before-edits event a few weeks ago. @JoelBennett came up with a good workaround on this post.

https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/inject-value-during-editing-workf...

GIS Developer
City of Arlington, Texas
JoelBennett
MVP Regular Contributor

That's not a bad idea...you could extend that workaround to include validation like so:

var featureLayer = new FeatureLayer({
	//etc
});

featureLayer.originalApplyEdits = featureLayer.applyEdits;

featureLayer.applyEdits = function(edits, options) {
	var errorMessage = null;

	//validate the values in the edits object; if validation fails, set a string value to the errorMessage variable, for example:
/*
	if (edits.addFeatures[0].attributes.name === "")
		errorMessage = "Name - value required";
*/
	if (typeof errorMessage == "string")
		return Promise.reject(new Error(errorMessage));
	else
		return this.originalApplyEdits.apply(this, arguments);
};
0 Kudos