Hey Jason,

2014-03-30 19:52 GMT+02:00 Jason H <scorp...@yahoo.com>:

> Hi. So I continue learning Wt and I'm onto the forms. I'm looking at the
> FormModel.cpp.
>
> Originally I was doing it the old, manual way. But I had several problems.
> One was it was just so hard to produce a "normal" looking form. If we refer
> the the" Create New User" form example, I observe that all the labels are
> right aligned and the forms fields are the same length. In my own manual
> trials, I got something that was either too small, or took up the whole
> width after the label. How do I properly control the form field width. For
> example, I want to add a "middle initial" WLineEdit field of length 1, and
> sized appropriately. How would I do that? As well as making the last name
> and MI on the same line as first name.
>

To keep the discussion simple, it's important to differentiate layout
issues from C++-organizational issues.

Layout of forms in HTML/CSS is frustratingly complex (especially with
features above, but add also responsive design, RTL, etc... and you're knee
deep in before you know) and no server-side technology can fix that.

That said, in Wt Auth we had to provide something with the library; the Wt
Auth module uses CSS from (resources/form.css) which at least gets some
things right, but may need to be extended for more features like what you
are asking for. Alternatively, using the bootstrap themes, there are some
tricks in bootstrap to layout forms (using their grid system). Or you can
combine a stand-alone 'grid' system with Wt.

Next, its just way too verbose. 360 lines for 7 form fields? When I was
> working in PHP I came up with a form class that used a simple layout
> template which the forms field objects were rendered into. This looked
> something like this (pseudo code):
>

Flexibility comes at a price. First of all, WTemplateFormView firmly
separates logic (including validation logic) from UI-related issues
(template / widgets). Secondly, it foresees that you can create a form
which encapsulates logic from different forms. The design of all this was
prompted by Wt::Auth, which for example has an 'update password form' that
uses at the same time an AuthModel (for authentication) and a
RegistrationModel (to enter a password), but also makes abstraction of
password-based authentication versus other authentication methods (like
OAuth).

And to be fair, a large chunk of the code is populating some models
(country, city) with data which wouldn't really be part of a realistic
implementation which reads this directly from a database.

form = Form(template)
>
> //Form::addItem(FormField ff);
> //FormField::FormField(formFieldName, labelContent, placeHodlerText,
> formInputWidget, validationFunction, dataModel);
>
> FormLineEdit("firstName", "First name", "enter your first name", new
> WLineEdit(), validatorNotBlank(), sourceModel(session()).user(),
> "firstName"))
> form.addItem(FormLineEdit("firstName", "First name", "enter your first
> name", new WLineEdit(), validatorNotBlank(), sourceModel(session()).user(),
> "firstName"))
> form.addItem(FormLineEdit("lastName", "Last name", "enter your last
> name", new WLineEdit(), validatorNotBlank(), sourceModel(session()).user(),
> "lastName"))
> form.show();
>
> I'm hoping we could do something similar?
>

Surely, you can do that, easily. And I do not think it's a bad idea either.
WTemplateFormView and WFormModel are in themselves relatively small
organizational classes. If you have different trade-offs than what we had
for Wt::Auth (which is almost surely the case), then it makes sense to
build your own form system on top of Wt (and WTemplate).

Also, I rue C++11. (Rant: This is because I am historically an embedded
> developer. Our compilers lag behind standards by 10 years or so and though
> C++11 is very cool and a good thing, and we'll eventually get support for
> it, I rather code be provided that runs on legacy compilers. Let those
> people that have C++11 compilers change it to C++11. But in the meantime,
> we are fracturing the C++ code base, which is a very wrong thing to do
> since the main attraction to anyone still using C++ these days is that it
> runs everywhere... End rant) Can we get a version that does not use C++11?
>

Yes. Everywhere there's a lambda you can put another function instead. But
then it will be more verbose :-)

The reason why we settled on C++11 for the widget gallery has actually to
do with making the examples self-contained functions that helped organize
the gallery (automatically showing code and working examples). But we've
also been pleasantly surprised by the uptake of C++11 by Wt users.

Regards,
koen
------------------------------------------------------------------------------
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to