AnsweredAssumed Answered

JavaScript Controller copy one field to another before blanking the first field

Question asked by Pat Pawlowski on Dec 1, 2016
Latest reply on Dec 2, 2016 by Michael Joyner

field_one is a drop down and field_two is a varchar. I want to be able to pick a value in field_one, have it populate field_two and then clear out field_one. Sounds simple enough. 


So I run this code in the on change event:

this.model.set('field_two', this.model.get('field_one'));
this.model.set('field_one', '');


Apparently Backbone is doing some kind of call back or something because the second line ends up finishing before the first and both fields end up blank. Other than using setTimeout, which is a kludgy work around, I don't see a decent way around this.  


If I comment out the second line then field_two gets populated correctly from field_one but field_one remains populated which isn't ideal but isn't exactly a show stopper either.


This is Sugar by the way and the Bugs module.