Create and Edit Sharepoint List in Spfx and React (Sharepoint Online)

%3CLINGO-SUB%20id%3D%22lingo-sub-2985652%22%20slang%3D%22en-US%22%3ECreate%20and%20Edit%20Sharepoint%20List%20in%20Spfx%20and%20React%20(Sharepoint%20Online)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2985652%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Microsoft%20Community%2C%3C%2FP%3E%3CP%3EI%20have%20a%20requirement%2C%20where%20we%20have%20to%20perform%20create%20and%20edit%20operations%20on%20SharePoint%20List%20Items%20using%20SPFX%20form%20and%20react%20framework.%20So%2C%20the%20issue%20is%20I%20have%20to%20show%20the%20List%20Item%20Data%20in%20SPFx%20form%20which%20I%20%E2%80%98am%20showing%20by%20passing%20ID%20through%20Query%20String%20but%2C%20all%20controls%20are%20in%20read-only%20mode%20(as%20values%20are%20populated%20of%20existing%20Item)%20and%20not%20able%20to%20edit%20.%20So%2C%20because%20of%20this%20issue%20even%20new%20form%20is%20also%20read-only%20as%20I%20%E2%80%98am%20using%20same%20SPFx%20form%20for%20both.%20%26nbsp%3BI%20saw%20many%20examples%20regarding%20CRUD%20operations%20in%20Internet%20but%2C%20they%20are%20all%20doing%20CRUD%20operations%20from%20browser%20but%2C%20I%20have%20to%20do%20the%20same%20in%20SPFx%20form.%20So%2C%20request%20you%20to%20let%20me%20know%20if%20anybody%20had%20resolved%20similar%20kind%20of%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2994826%22%20slang%3D%22en-US%22%3ERe%3A%20Create%20and%20Edit%20Sharepoint%20List%20in%20Spfx%20and%20React%20(Sharepoint%20Online)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2994826%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1224074%22%20target%3D%22_blank%22%3E%40nnn2612%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20sounds%20like%20you%20have%20already%20built%20your%20form%20using%20React.%20If%20so%2C%20perhaps%20you%20could%20post%20its%20source%20code%2C%20or%20at%20least%20a%20cut%20down%20version%20showing%20one%20or%20two%20fields.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20assume%20you%20have%20created%20an%20SPFx%20webpart%20to%20render%20your%20form%20and%20that%20you%20are%20reading%20the%20URL%20query%20string%20during%20the%20webpart's%20initialisation%20in%20order%20to%20find%20the%20ID%20of%20the%20list%20item%20you%20need%20to%20display.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20could%20use%20the%20presence%20of%20the%20ID%20query%20parameter%20as%20your%20condition%20for%20whether%20to%20display%20an%20existing%20list%20item%20in%20read-only%20more%2C%20or%20to%20display%20an%20empty%20editable%20form%20to%20be%20used%20to%20create%20a%20new%20list%20item.%20You%20could%20pass%20a%20property%20called%20readOnly%20into%20your%20React%20form%20component.%20When%20the%20React%20form%20component%20renders%20all%20the%20fields%2C%20it%20will%20use%20the%20readOnly%20property%20to%20determine%20whether%20to%20make%20the%20field%20editable%20or%20read-only%20(I%20assume%20the%20React%20controls%20have%20a%20read-only%20property).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20React%20List%20Form%20SPFx%20sample%20might%20be%20helpfule%20-%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2Fsp-dev-fx-webparts%2Ftree%2Fmain%2Fsamples%2Freact-list-form%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Esp-dev-fx-webparts%2Fsamples%2Freact-list-form%20at%20main%20%C2%B7%20pnp%2Fsp-dev-fx-webparts%20(github.com)%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Visitor

Hi Microsoft Community,

I have a requirement, where we have to perform create and edit operations on SharePoint List Items using SPFX form and react framework. So, the issue is I have to show the List Item Data in SPFx form which I ‘am showing by passing ID through Query String but, all controls are in read-only mode (as values are populated of existing Item) and not able to edit . So, because of this issue even new form is also read-only as I ‘am using same SPFx form for both.  I saw many examples regarding CRUD operations in Internet but, they are all doing CRUD operations from browser but, I have to do the same in SPFx form. So, request you to let me know if anybody had resolved similar kind of issue.

 

1 Reply

Hi @nnn2612 

 

It sounds like you have already built your form using React. If so, perhaps you could post its source code, or at least a cut down version showing one or two fields.

 

I assume you have created an SPFx webpart to render your form and that you are reading the URL query string during the webpart's initialisation in order to find the ID of the list item you need to display.

 

You could use the presence of the ID query parameter as your condition for whether to display an existing list item in read-only more, or to display an empty editable form to be used to create a new list item. You could pass a property called readOnly into your React form component. When the React form component renders all the fields, it will use the readOnly property to determine whether to make the field editable or read-only (I assume the React controls have a read-only property).

 

The React List Form SPFx sample might be helpfule - sp-dev-fx-webparts/samples/react-list-form at main · pnp/sp-dev-fx-webparts (github.com).