Friday, October 20, 2006

HTML::Widget versus RoR helpers

I've recently deleted lot's of code from InstantCRUD - some logic moved to templates, some to HTML::Widget::DBIC, some just simplified (with the help of uri_with). I am feeling the code for CRUD becomes quite 'elegant'.

What I am still not happy with is the widget config - I feel that all the visual things (like the choice between textarea and textfield etc) should be managed in the templates. The Ruby on Rails helpers seem ideal solution - they do all the validation, filling up the values that need to be done in the controller, but let the View manage the actual HTML produced. To reach that we would have be able to produce HTML::Widget::Element without specifying that it is to be a textfield or a radio box and leave the HTML generation to be called in the template, something like:

[% result.field_html('fieldname, 'textarea', cols, 30, rows, 5) %]

This would produce the field html with the proper value and an error mark if there was an error during validation. This looks like too radical step for evolution of HTML::Widget - perhaps what is needed is some completely new module?

Inspired by "Rails-like form helpers" email discussion.

There is a reply at the mailing list.


john.napiorkowski said...

I think you are putting the finger on some of the conceptual trouble I've had with HTML::Widget. It's a really great tool with a solid community, but for Catalyst development it's a little hard to figure out with a HTML::Widget is, since it has aspects that are both View-like (element type and layout controls) and Model like (constraints) with a bit of Controller tosses in for processing requests.

One of the things I like about JSF is how a form layout can be bound to a model in such a way so that you can have different templates to express that, such as plain or HTML forms, Ajaxified forms or even xforms based systems.

Anonymous said...

Yes, I agree with you. HTML::W is a great tool, but it's not so good for the auto generated code. People, especially in Perl community, want greater control of their code. I'd like to be able to move form elements around and do forms "my own way".

Anonymous said...

I've edited H::W, to make it possible to add a 'Field' type element to achieve this.

$widget->element(Field => foo);
$result->field_xml( foo => 'Textfield', %attrs );

which could of course be called from TT with:
result.field_xml( foo, Textarea, cols, 30, rows, 5 )

I haven't committed it to svn yet though, as I'd like to get some feedback first on what other sort of features you'd like, as I'm guessing some might require architectural changes.

btw, are you subscribed to the h-w mailing list? I sent a response to this blog post to the list last week. If you want to discuss this further, I'd much rather see the conversation happen there, where other h-w contributors hang out.
Carl Franks

john.napiorkowski said...

:) Actually I am on the list, just not sure of the best way for me to contribute based on my time needs (just got married, etc.)

I'll try to summarize my thoughts over there something soon.