FeroxTL
FeroxTL

Reputation: 5098

Multimple forms for one model backbone.js

The question is about managing models in forms on client with backbone.js

There is a model User on the server. It contains various fields:

I have a single page application of settings. There are two forms on it: "personal info" form and "other info" form. I although have an api, that contains two routes to handle it - /api/user/<id>/personal_info, /api/user/<id>/other_info (it could be changed, it does not matter). I can PUT or GET info from these apis.

So I can't decide how to organize my backbone models right. Right now I have two models - UserPersonalModel and UserOtherModel, each of them has it's own api and I save them apart from each other.

Am I doing right or I shall rewrite it to one js model UserModel and call different save methods like .savePersonal and .saveOther? What is the best practice?


This question came here from ru.stackowerflow.com

Upvotes: 0

Views: 25

Answers (1)

T J
T J

Reputation: 43166

Unless you're displaying multiple user forms at the same time and you'll have to do extra work mapping each other_info model with respective personal_info, I don't see any reason to combine those two as single model.
Especially since you have two endpoints, it's easier to have them as separate models, you can have separate view controlling each forms with respective models as well.

Combining the models will probably create nested attributes, then you'll have to manage that as well (Using plugins like deep model).

Upvotes: 1

Related Questions