I’ve been very quiet on the blogging front for the past few weeks. Although I would like to tell you that I have been relaxing on the beach somewhere, sipping cocktails and working a tan, it would be a lie. I have actually been spending my spare time creating a new open source project that I would like to introduce today.
The project I have been working on is called compaction, a small flex library designed to take some of the hard work out of creating CRUD based applications.
Some of the notable benefits of using the library include:
- Automatically detect user changes.
- Automatically undo user changes.
- Validate at the form level.
- Convention over configuration data binding.
- Disable buttons when validation fails.
- Disable buttons until changes have been made.
Although providing you with a lot of useful stuff, it has been designed to be as unobtrusive as possible. You can use compaction on a single form just like this:
<!-- The edit model does the heavy lifting --> <model:EditModel id="model" /> <mx:Form id="form" width="100%"> <mx:FormItem label="Name"> <mx:TextInput id="nameInput" /> </mx:FormItem> <mx:FormItem direction="horizontal"> <mx:Button id="saveButton" label="Save" /> <mx:Button id="cancelButton" label="Cancel"/> </mx:FormItem> </mx:Form> <!-- The binder wires the form components into the model --> <binder:FormBinder source="{model}" target="{form}" />
The edit model represents the state (editing, changed, valid, saving etc) of the editing process while the behaviour is encapsulated by a number of actions accessible from the model.
- model.edit (edit an object)
- model.cancel (undo user changes)
- model.save (persist user changes)
These actions are automatically enabled/disabled based on the state of the model. They also display useful tool tips when they are disabled to reduce confusion.
The form binder uses a convention over configuration approach to wire the form components into the model. I wont go into the conventions in this post but bindings on input fields are two way with user changes commited on “change” by default.
That concludes my very quick introduction to compaction, one of my main goals at this stage is to create a small sample application. I’d rather not reinvent the wheel here so if you know of an existing project that might benefit please let me know!