and cancel.. What's the best approach for this? I
copied the
onAnswer: block from another old Magritte email thread but its only
called when cancel is pressed.. Thx!
The #onAnswer: trick is the right thing to do here.
renderContentOn: html
component := (self session user) asComponent addValidatedForm;
onAnswer: [ :value | self answer: value ];
yourself.
html div id: 'fullwidthContent'; with: [
html div id: #fieldsetEnclosure; with: [
html render: component.
html submitButton
callback: [self answer: 'foo'];
text: 'Done'
]
]
The problem is that, #asComponent will create a new component every
time the page is rendered. So you need to move the code
component := (self session user) asComponent
addValidatedForm;
onAnswer: [ :value | self answer: value ];
yourself.
to #initialize of the component and answer component from #children.
Another problem I see is the #submitButton, that is outside the form
that you added with #addValidatedForm. To get your 'done' button into
the form you might want to customize the decorator like:
... addValidatedForm: #( save cancel done )
Now you need to add #done as an extension method to
MAContainerComponent to #answer: something meaningful. It's not that
nice, but it works ;-)
Btw, #save answers the changed model and #cancel answers nil.
Hope this helps,
Lukas
--
Lukas Renggli
http://www.lukas-renggli.ch