9.6Adding a Contact
We will modify the render method so that we can add a contact to our database, as follows. We add a callback associated with the text ’Add contact’:
ContactListView>>renderContentOn: html
html anchor
callback: [ self addContact ];
with: 'Add contact'.
html unorderedList: [
Contact contacts do: [ :contact |
html listItem: [ self renderContact: contact on: html ] ] ]
ContactListView>>addContact
| name emailAddress |
name := self request: 'Name'.
emailAddress := self request: 'Email address'.
Contact addContact: (Contact name: name emailAddress: emailAddress)
You should now have the Add contact link as shown in Figure 71.
Here we’ve made use of the WAComponent>>request:
method to display a message for the user to enter a name, then another message for them to enter an email address. We will discuss the request:
method in Part III. Note that a real application would present a form with several fields to be filled up by the user.