Select to view content in your preferred language

Validate Editor widget Edits Before Saving

195
0
04-19-2024 06:06 AM
RichardRhone1
New Contributor

Good Day, 

I have added the Editor and it is working. However, i would like to validate the user inputs before it saves/updates/ commit. Please assist.

 

 

var editor = new Editor({ view: view, layerInfos: [editParcel], visibleElements: { snappingControls: false }, container: document.createElement("div") });

view.popup.on("trigger-action", function (event){ if (event.action.id === "edit-this") {selectFeature(view.popup.selectedFeature.attributes.fid); }
});

function selectFeature(num){
if (!editor.activeWorkFlow)
{
view.popup.visible = false; 
editFeature = view.popup.selectedFeature;
editor.startUpdateWorkflowAtFeatureEdit(view.popup.selectedFeature);
view.ui.add(editor, "top-right"); console.log("EDITOR ", editor);
}
reactiveUtils.when(() => editor.viewModel.state === "ready", () => { view.ui.remove(editor);  });
}//end function

// Watch when the popup is visible
reactiveUtils.watch(() => view.popup?.visible, (event) => { if (editor.viewModel.state === "editing-existing-feature") { view.closePopup(); } else { features = view.popup.features; } });

 

/////////// MY ATTEMPT -> UNSUCCESSFUL;;  DATA STILL UPDATED

parcelLayer.on("apply-edits", (event) =>
{

const validd = validData(editFeature.attributes);

if (validd == false) { return;}

else
{

view.ui.remove(editor);
// Iterate through the features
features.forEach((feature) => {
// Reset the template for the feature if it was edited
feature.popupTemplate = editablelPopup;
});

// Open the popup again and reset its content after updates were made on the feature
 if (features) { view.popup.open({ features: features }); }

//Cancel the workflow so that once edits are applied, a new popup can be displayed
editor.viewModel.cancelWorkflow();

}//end else

 

});

0 Kudos
0 Replies