caveman icon indicating copy to clipboard operation
caveman copied to clipboard

Form generator

Open fukamachi opened this issue 13 years ago • 4 comments

fukamachi avatar Apr 22 '11 05:04 fukamachi

A famous form generator on Rails:

https://github.com/justinfrench/formtastic

m2ym avatar Apr 25 '11 03:04 m2ym

I like simpleform, in addition to formtastic.

https://github.com/plataformatec/simple_form

sfsekaran avatar Feb 16 '13 08:02 sfsekaran

What is an acceptable way to implement this? I don't think we can achieve the same way of integration as those rails plugins can. Because the templating system less integrated with the framework as is the ORM.

An example of how you would create forms using ruby

In ruby you have the form_for method that creates a form. You use this method within a view, this view is coupled to a Controller and to a method of a controller. So app/views/users/new.html.rb is coupled to UsersController#new.

This form_for method takes at least one arguments, a record. So in our example form_for(@user) would use the @user instance variable of UsersController after calling UsersController#new. It now checks if this user exists using the #persisted? method. After all this it creates the form with a optional input field for key method which is set to patch. If this form is uploaded it is routed to the correct method once again using the action table. Now we can simple use the model class to create a new user (with filtered params of course). If this failed we can simply render new again.

Because the ORM is embedded in rails the creation will only fail if certain 'model validations' failed. These also fill the error hash-table for the user with Error objects. These validations also contain an error message (by default of specified) and these are shown to the user if wanted.

So in conclusion: this is very hard with caveman. Caveman is not tightly integrated with an ORM or templating engine. The ORM it has does do any form of validations, so easy creation of objects using a form generator is hard. Also caveman does not force the use of controllers, so generating a form and using this on many webpages is also harder, as we don't know what fields to add because we don't know with what kind of class/struct/model we are working. And finally how should we pass the forms to the templates? Using variables will be very slow if a website has many forms (all forms have to be generated for each request), and other ways (custom djula tags) will mean that using other templating engines will become harder.

I think to only way to have a nice form generator is to chose a real ORM and a default templating engine and become more opinionated about how applications should be formed and routed. However this would probably break compatibility, so doing this for caveman2 would be impossible.

libre-man avatar Oct 16 '16 12:10 libre-man

Linking to some CL web form validators that I didn't find easily:

  • https://github.com/inaimathi/formlets - last update nov 2016

Automatically validating formlets for Hunchentoot + cl-who

  • https://github.com/mmontone/cl-forms - last commit 2 days ago

Although it is potentially framework agnostic, it runs on top of Hunchentoot at the moment.

  • https://github.com/tshatrov/1forms - last commit 2 years ago

It can be used with various Common Lisp web servers and web frameworks such as caveman2. 1forms uses CLOS and is extensible by design.

vindarel avatar Jul 29 '17 10:07 vindarel