Sure. You can create a portal on this layout (you may want to make the layout a little bigger first) showing all your contacts.
Showing All Contacts
To do this, create a new table occurrence of your contacts table on the graph and call it "SampleEvents_AllContacts". Then relate this to Sample Events by linking the EventID with the ID in your Contacts table using the "x" operator: this kind of relationship shows all records.
Now format your portal as you see fit and add a "select" button in the portal row. This button will link the current event to the contact you click on. Have this button set the event's contact ID key (the field _id_contact in our sample data) to the following calc where _id is the unique ID in your contacts field:
- Code: Select all
If (
SampleEvents::_id_contact = SampleEvents_AllContacts::_id ;
"" ;
SampleEvents_AllContacts::_id
)
That if statement de-selects the contact if they are already linked to that event.
Going Further: Conditional FormattingYou can add conditional formatting to the portal to highlight the selected contact. Since only text-like objects can be conditionally formatted, it helps if the button you created above to select the contact was made using the button tool and that fills the whole portal row behind the contacts name. Once it does, add conditional formatting to turn it blue when...
- Code: Select all
// Contact is selected
SampleEvents::_id_contact = SampleEvents_AllContacts::_id
Add the same conditional formatting calc to the contacts' name in the portal, turning the text white when the contact is selected.
Going Further: Type-ahead Portal FilteringIf you're using FileMaker 11 you can also easily add a type-ahead to this portal so that as you type in the first few letters of the contact's last name, the portal shows just the contacts who match what you're typing.
Begin by creating the field you'll type into: create a global text field in SampleEvents called z_ContactTypeAheadGlob. Make this a text field and set it's options to Global storage. Place this at the top of your portal as shown below.
Now double click on your portal of all contacts and check "Filter portal records". Click "Specify" and add this as the filter criteria:
- Code: Select all
Let ( [
n = Length ( SampleEvents::z_ContactTypeAheadGlob )
] ;
Left ( SampleEvents_AllContacts::NameFull ; n ) = SampleEvents::z_ContactTypeAheadGlob
)
Now filtered portals don't refresh on their own, so we'll need to add a script trigger to refresh this as you type. Create a new script called "Contact Type Ahead" with the following steps:
Commit Records/Requests []
Refresh Window [Flush cached join results]
Go to Field [SampleEvents::z_ContactTypeAheadGlob]
Now enter layout mode and assign a script trigger to the "z_ContactTypeAheadGlob" on your layout, right click on the field and select "Set Script Triggers". Add an "OnObjectModify" trigger, and call your "Contact Type Ahead" script.
That's it! Our version looks like this:
Hope that helps,
John