Formula: Building nice validated forms in Iliad with ease

Tagged:

Building forms is a long, boring and repetitive task.

Hopefully you can use Magritte, a nice meta-description framework which builds forms for your models for you. The problem is that sometimes Magritte is not what you want. You may not want to add class side descriptions to your models everywhere, if all you need is a few forms to edit them.

Another problem is that you end up writing parts the UI in the model. If you reuse your descriptions everywhere it makes sense to avoid duplicating your code, but sometimes those descriptions are just there to build some forms, and at the end it doesn't feel right.

Trying to solve this problem, I wrote a small package for Iliad named Formula. Formula doesn't try to compete with Magritte, it's not about descriptions, just about building forms. It contains widgets for forms, fields and conditions.

As an example is often better than a long speech, the todo list example in Iliad now uses Formula to edit list items:

formula := ILFormula on: anItem.

(formula dateInputOn: #deadline)
        label: 'Deadline'.

(formula inputOn: #title)
        labelContents: [:e | e span class: 'required';text: 'Title'];
        addCondition: [:val | val notNil and: [val notEmpty]]
        labelled: [:val | 'This field is required'].

(formula textareaOn: #body)
        labelContents: [:e | e span class: 'required';text: 'Body'];
        size: 30@10;
        addCondition: [:val | val notNil and: [val notEmpty]]
        labelled: [:val | 'This field is required'].

(formula checkboxOn: #completed)
        label: 'Completed'.

The main widget is ILFormula. It will actually build the form. The class has convenience methods to add form fields, like #inputOn: or #passwordOn:, and each field can be customized through #label:, #comment: or #labelContents and #commentContents:.

The screenshot below shows how it looks like with a bit of css:

You can get the code of Formula in Iliad/More/ in the latest git version of the github repository.

I like this approach. It's compact.

How about working on collections, i.e. for an indeterminate (and changing) number of items that are editable?

s.

Sorry for the (very) late answer.

Wouldn't this be enough:

aCollection do: [:each |
    formula inputOn: each asSymbol]

Nico

User login