|
 Ludwig Ruderstaller - 2008-03-31 16:33:55
Hi Manuel,
again, a tricky task. I have a "paged" form, on one of the tabs i should have repeating blocks of 2 formfields. (eg. a region and an interest select) the User should be enabled to add an infinite number of this form groups.
My aproach so far is to simple write the HTML code via innerHTML on ajax request, one of the problems lies within validation and prefilling the form.
the formgenerator doesnt know about the new selects, which would be ok in a perfect world, where users dont make strange inputs :-)
the other problem is to add an element to an already existing element. (adding the field to the auto_layout)
do you know of a way to accomplish this ?
TIA
Ludwig aka Rufinus
 Manuel Lemos - 2008-04-06 04:03:44 - In reply to message 1 from Ludwig Ruderstaller
Currently there is no way to achieve that in an easy way.
I think it is an interesting feature but it is a bit complicated because each input is more that the HTML that is necessary to display it. It is also the Javascript code to validate it.
I need to think on good way to implement that with all the necessary implications.
Maybe the class should provide a way to create clone of an existing input, overriding just some properties and insert or append it into some HTML tag node perhaps formatted with a given HTML template. Then the class should be able to figure what HTML needs to be inserted and what Javascript should be called to validate the input.
This would not solve the problem of figuring what new fields were added on client side before submitting.
Maybe there should be a sort of array custom input plug-in that manages a variable number of inputs.
I need to think this further to avoid eventual design mistakes. Anyway, I wonder if this would address your needs.
 Ludwig Ruderstaller - 2008-04-16 18:02:13 - In reply to message 2 from Manuel Lemos
Hi,
In my special case i wouldn't need clientside validation (couse i dont use it at all).
but in general you're right. for some other reasons then clientside validation it would be good to know the fields which where added with ajax on the clientside.
> Maybe the class should provide a way to create clone of an existing input,
This was also my very first aproach. And it seems to be the best one. Declare a field or a set of field as "cloneable". This wouldn't need an ajax call, it is doable just on the client. And as you said, store the information of how much clones there are in a special field for leting the formgen-class know how many clones of this field are present. This would match my case 100%. Of course this only works for repeating fields. And not for fields which should be added based on clientside action. (but on the otherside, this could be handeld with hidden fileds, like in one of your examples)
At the moment i use a very dirty aproach. I save the ajax-added-fields in the session, and when the form has to be redrawn (eg. serverside-validation fails) the form-definition is extended based on the information in the session. In case of editforms (load input values) i count the array of the values and add the fields dynamicly to the formgen class.
Ludwig
 Manuel Lemos - 2008-04-17 04:32:33 - In reply to message 3 from Ludwig Ruderstaller
Well, cloning just the input is not enough. Other than the validation, you also need to take care of the layout of the input, also labels and eventually things that may not be the same in the clone, like HTML elements ID tags.
So, I am still not sure what would be the best way to solve this problem in a generic way that does not impose serious constraints to developers.
Maybe when I have a real world problem that dynamic input insertion would be necessary, I will figure a more robust solution.
|