0

I would like to know if it's possible to call multiple @configure calls or conditionally inside a spine.js model. This would allow the model to be reused in case where there two different forms that could benefit from using the same model. Is there an other way of achieving this in spine.js?

Thank you in advance for your time and effort.

Panos Spiliotis
  • 801
  • 1
  • 9
  • 18

1 Answers1

1

Diving into the spine library you can see that configure() will overrule any previous configuration. It sets the className and attributes and clears the current records which were stored in the model.

I don't think that you would want this in any case. It would simply define another model, which sounds like the thing you want to do. A model shouldn't change on the fly.

If you are trying to use forms to set different fields on a model, you can simply use a configuration with all fields and apply the forms on the model.

class ExampleModel extends Spine.Model
  @configure "ModelName", "field1", "field2"

And a simple form like this

<form>
  <input type="text" name="field1"/>
</form>

Now you could take the values from this form and store it in your model.

modelInstance = ExampleModel.fromForm($('form'))

This would just store the field1 attribute on your new model instance.

A little more details on the use-case would be nice.

This might help: Forms documentation

Michiel
  • 234
  • 2
  • 12