mardi 10 juillet 2018

Form handling in javascript

I am bad at organizing my javascript code. I've build a js app that handles different type of orders of a bike renting app, like:

  • customer orders
  • maintenance orders
  • transport orders
  • etc.

Also the transport orders can have order sub-types: - internal transport - transport from customer - transport to customer

In my front end I have to deal with creating/updating any order type. All orders share some fields like:

  • picking location
  • delivery location
  • employee
  • start date
  • appointment date
  • etc.

At the beginning my two html forms create/update and the spaghetti code did just fine, but I got intro problems when each order type changed it's requirements and needed a different html view. On update, for example I load the order data into the update form and I configure the form view depending on the order type by hiding/showing inputs.

I took a look at js inheritance, factory pattern, mvc but I didn't get a clear big picture on how to implement all of this. Also I came across this article https://www.awwwards.com/build-a-simple-javascript-app-the-mvc-way.html. What should the view be represented by? What should the model be represented by?

So therefore I ask you how should I organize my js code in a reusable way? I am not using any js library or framework.

Aucun commentaire:

Enregistrer un commentaire