Is there any way to autopopulate form fields based on a JSON file that will be uploaded via a Load button in ReactJS - reactjs

I am trying to make an application that would have a form that gets autofilled once the user uploads a JSON file and clicks the load button , so I was wondering if there's any way to achieve this .
Thanks

That's totally possible. Just make the file upload write a JSON to state (https://www.geeksforgeeks.org/file-uploading-in-react-js/) and then when the user clicks a button, scan through the uploaded JSON for the relevant keys. When you find a key, just use the value associated with it and set the state value of the associated form element.

Related

How do we set the entire form data as a hidden input field value in reactJS (using react-json-schema-forms, react-admin)

We are using JSON Schema to Form library to embed a form inside a reactJS page.
We want to set the form (generated from JSON schema) data into a input hidden value to be used later on to pass to a service to save the form value in the database.
e.g.
See the formData highlighted in the image below attached. this needs to be set as a value to passed to save in the database column
enter image description here

Use one json file instead of two Angularjs

I load data from two json files based on radio button value...It's working fine ..But now I want to use one json file instead of two...I mean having both json data in one json file and we load acording to rado button value.How can I do that?

Send file to server through iText PDF?

I'm dynamically creating some PDF files through my application, using iText, and I need to use several components (TextField, CheckBox, RadioButtons etc), and then submit the values to server. But, one of the requirements says that the user needs to be able to select and send files along with the other values. I did not find a specific component to this, and so I'm asking for some help with this situation.
Is there a way to create some kind of Input File, File Chooser, etc, and attach it on the generated PDF file? And then send this selected file to server?
Thanks
This is explained in the official documentation, more specifically in the example FdfServlet of chapter 9 of my book. However, in this example, we add a file selection field to an existing PDF, so I've made you an example that explains how to create such a field when creating a document from scratch: FileSelectionExample
A file selection field is created just like any other text field, except that you have to set a flag using the setOptions() method. If you want a file chooser to appear, you also have to add a JavaScript action:
TextField file = new TextField(writer, new Rectangle(36, 788, 559, 806), "myfile");
file.setOptions(TextField.FILE_SELECTION);
PdfFormField upload = file.getTextField();
upload.setAdditionalActions(PdfName.U, PdfAction.javaScript(
"this.getField('myfile').browseForFileToSubmit();", writer));
writer.addAnnotation(upload);
In the full example, I also added a second field and after selecting the file with the browseForFileToSubmit() method, I set the focus to that other field. I'm doing this because the file name only becomes visible in the file selection field after that field loses focus.

TextProperty field in NDB gets "=" appended after every line

I have very strange case which I wasn't able to debug for a day.
On my front-end I have form with textarea and submit button.
On submission, the textarea field gets saved as ndb.TextProperty()
When I submit a multiline text, the text in the database gets = or =20 characters on every line. At first I thought they get randomly inserted, but it seems every 76 characters gets one = character.
This gets really hard to debug as on my localhost instance it works perfectly fine, but on the deployed version it doesn't. They are both in sync. Also on my localhost instance the text field on the datastore entity shows correctly the newline and tab characters, but on the deployed version, the datastore field is shown as one text blob without newlines or tabs.
Anyone can guide me to the right direction ?
Oh, BlobStoreHandler you didn't mention that in your original question.
Ok there is your problem.
I don't believe you can combine the two. If you are uploading to the Blobstore you can't do other form elements, as the upload is directed to the BlobStore service.
From the docs
The user creates a blob by submitting an HTML form that includes one
or more file input fields. Your application calls create_upload_url()
to get the destination (action) of this form, passing the function a
URL path of a handler in your application. When the user submits the
form, the user's browser uploads the specified files directly to the
Blobstore. The Blobstore rewrites the user's request and stores the
uploaded file data, replacing the uploaded file data with one or more
corresponding blob keys, then passes the rewritten request to the
handler at the URL path you provided to create_upload_url(). This
handler can do additional processing based on the blob key.
So it's difficult to say exactly what is going on without seeing your code, but I seriously doubt you can do what you are trying to achieve.
I've also had the same problem,
I solved it in a way that isn't elegant, but functional:
I did a replace on the input;
here is the code
input_html_text = unicode(self.request.get('text')).replace('=\r\n', '')

How to add a simple 'save' button to bespin editor?

Followed the simple tutorial from here
Settings of Bespin embedded?
But cannot figure a way to add a 'save' button that would trigger an ajax event or whatever so i can process it and save the content to a file.
Any clues ?
What you'd want to to go here is get a handle to the text value of the editor in javascript and post that server side to save either as a file or in a db.
You can get the editor text value this way:
var editor = env.editor;
var value = editor.value;
One easy trick would be to copy that value to a hidden field so you could process it like you might any other form field.

Resources