I’m modelling a form embeeded inside a modal and I’d like it to be reset when my route calls reset explicitly in the controller. This is somehow the form Im managing inside a modal:
{{#modal-window title='Size management' close='removeModal'}}
<label>
<span>Size</span>
{{input value=width class='width'}}
<span>X</span>
{{input value=height class='height'}}
</label>
<label>
<span>Left</span>
{{input value=left class='left'}}
</label>
<label>
<span>Top</span>
{{input value=top class='top'}}
</label>
{{/modal-window}}
This is the controller that presents/manages the form:
App.SizeEditorModalController = Ember.ObjectController.extend
width: Ember.computed.oneWay 'model.width'
height: Ember.computed.oneWay 'model.height'
top: Ember.computed.oneWay 'model.top'
left: Ember.computed.oneWay 'model.left'
reset: ->
# I'd like to restore the oneWay properties to its default values coming from the bound model
This is the route that shows the modal resetting previously the controller involved.
App.ApplicationRoute = Ember.Route.extend
actions:
showModal: (name, model)->
controller = @controllerFor name
controller.reset()
@render name,
into: 'application'
outlet: 'modal'
model: model
removeModal: ->
@disconnectOutlet
outlet: 'modal'
parentView: 'application'
When I set some values to the form controls, they stay there forever, because I’m using oneWay properties and I don’t know if exists any way of resetting those properties to get the values from the source binding again. I don’t want the model to be updated before clicking ‘Save’ button. This is a quite common situation and I’m sure Ember has an easy way of achieving this, but, at the moment I cannot see what is this way.
Thanks in advance