SPFx web part form validation

%3CLINGO-SUB%20id%3D%22lingo-sub-379186%22%20slang%3D%22en-US%22%3ESPFx%20web%20part%20form%20validation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-379186%22%20slang%3D%22en-US%22%3E%3CP%3EWe've%20built%20several%20web%20parts%20using%20SPFx%2C%20React%2C%20and%20the%20Office%20UI%20Fabric%20React%20controls%20to%20replace%20existing%20InfoPath%20forms.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20are%20people%20using%20for%20form%20validation%3F%20Is%20there%20a%20popular%20JavaScript%20library%20for%20React%20forms%20that%20works%20well%20within%20the%20constraints%20of%20SPFx%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20found%20InfoPath%20rules%20to%20be%20very%20powerful%20and%20fast%20to%20implement%3B%20writing%20it%20out%20in%20JavaScript%20logic%20has%20proven%20rather%20difficult.%20We're%20writing%20validation%20onBlur%20or%20onChange%20from%20most%20of%20the%20Office%20UI%20controls%20---%20but%20managing%20overall%20form%20validation%20through%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fmedium.com%2F%40MCapoz%2Fpassing-data-in-react-with-prop-drilling-904aeb3cb5e%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eprop%20drilling%3C%2FA%3E%2C%20which%20creates%20really%20messy%20React%20architecture%20as%20Office%20UI%20controls%20deep%20in%20components%20still%20need%20to%20report%20back%20their%20validity.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20wondering%20what%20others%20have%20found%20that%20worked%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20contributing%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-678041%22%20slang%3D%22en-US%22%3ERe%3A%20SPFx%20web%20part%20form%20validation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-678041%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F305327%22%20target%3D%22_blank%22%3E%40joseph_crockett_doe%3C%2FA%3E%26nbsp%3BI%20am%20also%20building%20SPFx%20web%20parts%20to%20replace%20legacy%20forms%20and%20doing%20manual%20validation%20on%20each%20component.%20I'd%20love%20to%20know%20an%20easier%20way.%20I%20am%20also%20struggling%20with%20the%20inconsistency%20in%20the%20properties%20available%20for%20validation%20in%20the%20different%20components.%20For%20example%2C%20the%26nbsp%3B%3CSPAN%3EvalidateOnFocusOut%20and%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EvalidateOnLoad%20properties%20exist%20for%20the%20TextField%20component%20but%20not%20the%20Dropdown%20component.%20I'm%20hoping%20for%20some%20consistency.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-787258%22%20slang%3D%22en-US%22%3ERe%3A%20SPFx%20web%20part%20form%20validation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-787258%22%20slang%3D%22en-US%22%3EI%20would%20use%20formik%20%3CA%20href%3D%22https%3A%2F%2Fjaredpalmer.com%2Fformik%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fjaredpalmer.com%2Fformik%2F%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Ewith%20ui%20fabric%20controls%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fkmees%2Fformik-office-ui-fabric-react%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fkmees%2Fformik-office-ui-fabric-react%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-787723%22%20slang%3D%22en-US%22%3ERe%3A%20SPFx%20web%20part%20form%20validation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-787723%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you're%20using%20the%20latest%20version%20of%20React%20(16.8%20%26gt%3B)%20then%20I'd%20have%20a%20look%20at%20React%20Hooks%20-%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Freactjs.org%2Fdocs%2Fhooks-intro.html%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Freactjs.org%2Fdocs%2Fhooks-intro.html%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EHere's%20a%20good%20example%20of%20using%20hooks%20for%20form%20validation%2C%20without%20the%20need%20for%20any%20other%20libraries%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fupmostly.com%2Ftutorials%2Fform-validation-using-custom-react-hooks%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fupmostly.com%2Ftutorials%2Fform-validation-using-custom-react-hooks%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-788426%22%20slang%3D%22en-US%22%3ERe%3A%20SPFx%20web%20part%20form%20validation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-788426%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F861%22%20target%3D%22_blank%22%3E%40Toby%20Statham%3C%2FA%3E%26nbsp%3BI%20will%20take%20a%20look.%20I%20heard%20about%20this%20recently%20from%20someone%20else.%20Thanks%20a%20bunch!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Visitor

We've built several web parts using SPFx, React, and the Office UI Fabric React controls to replace existing InfoPath forms. 

 

What are people using for form validation? Is there a popular JavaScript library for React forms that works well within the constraints of SPFx? 

 

We found InfoPath rules to be very powerful and fast to implement; writing it out in JavaScript logic has proven rather difficult. We're writing validation onBlur or onChange from most of the Office UI controls --- but managing overall form validation through prop drilling, which creates really messy React architecture as Office UI controls deep in components still need to report back their validity.

 

I'm wondering what others have found that worked? 

 

Thank you for contributing

4 Replies
Highlighted

@joseph_crockett_doe I am also building SPFx web parts to replace legacy forms and doing manual validation on each component. I'd love to know an easier way. I am also struggling with the inconsistency in the properties available for validation in the different components. For example, the validateOnFocusOut and validateOnLoad properties exist for the TextField component but not the Dropdown component. I'm hoping for some consistency.

Highlighted
Highlighted

If you're using the latest version of React (16.8 >) then I'd have a look at React Hooks - https://reactjs.org/docs/hooks-intro.html 

Here's a good example of using hooks for form validation, without the need for any other libraries

 

https://upmostly.com/tutorials/form-validation-using-custom-react-hooks

Highlighted

@Toby Statham I will take a look. I heard about this recently from someone else. Thanks a bunch!