Update a form that is generated dynamically based on api response - javascript

I'm building an admin dashboard that has the option to update products. Each product has different attributes. I have already retrieved the data from the API and rendered it but I'm thinking about how I can update it as each product has different properties and I can not know what attributes I will need to update. So my question is how can I manage state and retain all values of the input fields and then post it back to the api.

Related

Use AJAX and Controller to Populate Index page by Dropdown Selection

I have an ASP.Net Core project and I used EntityFramework to scaffold using CRUD. I have my view pages and I want to make my index page dynamic. I have a hierarchical database where it is in this order, Department, SubDepartment, Machine, Equipment, Problem. I have already made queries for different views where I return data based off a dropdown selection. My question is how do I enter queried data into the table to display in Index?
There are many options and I am not sure where to start. Here are some of my thoughts.
Return the queried data to the view as a JSON and sort of manually parse it into the table.
I am not sure on this one but could I just add the queried data into a ViewBag or ViewData and it would automatically be added to the table?
As of now, I already have a JSON that is being returned into the view.
EDIT: I just remembered that ViewBag/ViewData is likely not an option because to my understanding those require a page refresh. So my question now is how can I parse a JSON into a EntitityFramework created table?

Can you create forms to store information with React-Admin?

I am trying to create a form to get information that will only be stored but not displayed using React-admin.
So far, I have only seen forms in react-admin when you want to add information to an existing table or if you want to edit information. Is there a way to have the form appear as the first thing and only POST information?
Yes, when defining your resources under your <Admin> component just set the list prop to be your Create form.
<Resource name="my_resource" list={MyCreateComp} />
As long as your resource has a value for list it will show up in the menu.
More info in the react-admin resource docs

How to edit and save a reactive form in Angular 2?

I have built a reactive form, and persisting the data, at initial step I would be saving the form with initial set of data.
for eg:- I have an array of objects as below :
[{Name:'Tom',age:'25',subject:'maths'}].
On saving this to DB, I will be getting a unique ID, Say Student ID.. By using this ID I would need to edit the Data..
Could you please help me how I should be editing the data and save back
P.S., I have a data service where I will be temporarily storing the data and getting the data.

Edit in Ember with Ember data an object and its sub-collection in one form

I am working on an application with Ember + Ember Data.
I have a model "Tax" with a collection of "Sub-Regions".
I also created a list of tax objects, with an Edit button. When a user goes to edit, I have created a form, that has fields for the properties of Tax, as well as a list of Subregions with a text input field to modify the default tax rate for the subregion. What I would like to do is to be able to save in one action the object Tax and all the items of the sub-collection. I'm stuck creating that action, not sure how to approach that problem.
I've put a sample here: http://emberjs.jsbin.com/jinovi/6/
I come from a back-end background and I know how I would solve it using MVC with page refresh, but not sure how to do it in Ember.
I've noticed that it gets all saved locally because I'm using Fixtures, I guess that if I use the REST adapter it will work in the server too.
I've put a sample here: http://jsbin.com/jinovi/8/

How can i use REST in python django for multiple tasks

This is the first time i am using REST for any web applications.
For normal get an post and i simply call the API done in Django Rest Framework.
But i am not able to think how can i deal with situations where something more needs to be done.
Suppose I have
List of users in database and their product they have bought.
Now i have web form where if someone adds the user and then submit the button , then
I have to get the list of items bought by that user in 5 hour window
Update the row in database which says buy_succeessful to false
Then again get the list of orders from the items he has bought and then update the rows with order_successful to false
Now current in my submit actions i am doing like
call to api to add the user in override manual enrty table. This is simple post to that table
Then after getting the sucessful tehn i again call api to list of items this user has bought using Query parameters . Then i have the list
Then again i loop through the list and post to api for updating that record in datbase
and so on
I am feeling this is not right.
I have found that quite often there are some more things to do tahn just saving individual objects in database.
whats the best way to do that. DO i need to have view api for every function
Try the 3rd step of the DRF Tutorial:
http://www.django-rest-framework.org/tutorial/3-class-based-views
Here, it shows how to do a "PUT" request for updating data. And also some of the other DRF features.
Also, you can reference serializer.object which is the object instance of the django model record that you are saving to the database. This question here talks about adding extra attributes, etc... before saving to the database:
Editing django-rest-framework serializer object before save
You can also access the record post_save and there are other hooks in the framework that you can use.

Categories

Resources