pnp / sp-dev-fx-controls-react

Reusable React controls for SPFx solutions
https://pnp.github.io/sp-dev-fx-controls-react/
MIT License
380 stars 379 forks source link

DynamicForm - Possibility to add error messages below specific fields #1298

Open SmarterJB opened 1 year ago

SmarterJB commented 1 year ago

Category

[x ] Enhancement

[ ] Bug

[ ] Question

Version

3.10.0

Expected / Desired Behavior / Question

Possibility to write error messages below each field when stopping the save in the onBeforeSubmit method. It would be nice to maybe return an object like {"internalFieldName":"This is an error message!"} and the dynamic form would render the message below the affected field.

Another possibility would be to create the object with all internal field names in the dynamic form, and hand it over to the "onBeforeSubmit" method for the user to add an error message to each field.

onBeforeSubmit={(listItemData, fieldValidationInfo) => {
      if(listItemData["internalFieldName"] !== "Title"){
        fieldValidationInfo["internalFieldName"] = "The value of this field needs to be 'Title'!"
        return true;
      }

      return false;
    }}

This would greatly improve the usability of the dynamic form!

If we decide how it should be done, I would be glad to implement the feature myself!

Observed Behavior

Currently you can only put an error message underneath or above the whole DynamicForm.

Thanks!

ghost commented 1 year ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

b247 commented 1 year ago

Hello, is there a way to access (v3.12.0, DynamicForm, the onBeforeSubmit method) - all formData? I'm looking to perform advanced form validations based on all formData/submitted data and not just data from one/few changed fields.

@SmarterJB Another possibility would be to create the object with all internal field names in the dynamic form ...

I guess what I'm looking for is exactly this?

@SmarterJB ... I would be glad to implement the feature myself!

@SmarterJB, me being on my first steps on the spfx and react world, can you please give me a hint/help on how advanced validations can be performed on spfx form customizer extension (using DynamicForm - onBeforeSubmit). 🙏

michaelmaillot commented 10 months ago

Hi @b247,

I gave a code snippet here following a request about handling min / max values specified on the SP fields.

Even if there's nothing provided by the Control to handle fields validation on demand, you can always check fields values and potentially cancel form submition.

Hope that it helps.