P
P
psyhO_octopus2015-05-18 18:33:12
JavaScript
psyhO_octopus, 2015-05-18 18:33:12

How to "untie" related fields in Backbone models?

I have a date component in which you can select a time period and a model in which there are three fields:

  • startDate - the beginning of the period
  • endDate - end of period
  • period - some number equal to the number of days. You can choose the day, week, etc. and then its value will be 1, 7, etc. respectively

For each model field there is a corresponding interface element.
The algorithm of work is the following:
  1. I changed the period:
    • endDate - stays the same
    • startDate - calculated as endDate - period
    • the control that displays the value of the period field must display the corresponding period
    • controls that display the values ​​of the endDate and startDate fields are also updated

  2. I changed startDate:
    • period - reset because it is no longer equal to some preset value
    • the control that displays the value of the period field should "reset"


And here is the most interesting. When I update, for example, the period field, both the endDate and startDate fields should be updated, and updating them immediately leads to updating the period field to an empty value, which, of course, is not true.
And the question is how to overcome it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question