Hi
I am struggling with how to best edit data in a repeating group.
I have built an article builder which allows a user to create articles and insert specific sections for call outs, quotes, images etc.
The idea is, the user adds a section, adds text to the section, adds another section and so on.
This is fine. The issue i have is updating the article.
Currently i have set autobinding on the input in the form so the data base is updated straight away. This is for text and images. Te article section thing has a type which records the type of section (body, image, quote, call out, etc) an image field to record and display an image and a text field to record the text to display in the section.
But, if the user opens the editor, makes changes, and then does not want to save those changes i need a way to revert the data.
I have tried setting a state that is a list of texts to record the opening data, but I could n’t get to where i needed with it, and i struggled with the list of images (which also have a text caption). Also, and i think i’m missing something, i tried to push the states to the inputs but I couldn’t work out how to update the states in the individual inputs.
My solution was to create a temporary record that replicates the section. If a user presses save after their updates then everything is as is. If they x out and do not save the updates, I loop over the temporary records and compare them to the actual, then update appropriately.
Whether the user saves or not, all temporary records are then deleted - if save occurs, they are deleted immediately, if user x outs, once i have looped over the record to compare with original i then delete it.
This seems quite resource intensive and wondering if anyone could point me in a better direction at all. Or if what i am doing is reasonable?