is not used any more and exists only for history. Post new tickets on the Github account. n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 12 years ago

Last modified 10 years ago

#1071 assigned enhancement

jForms : add methods to the API to help manage reference count introduced in #876 fix — at Version 2

Reported by: bricet Owned by:
Priority: normal Milestone:
Component: jelix:forms Version: trunk
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:

Description (last modified by laurentj)

Since #876 fix, jForms now have an internal counter to manage multiple create without any delete. This could happen, for example, if a user opens several browser windows/tabs of the same Jelix page. What is expected from the user is to be able to use whatever window/tab he wants, may be several if your application can handle with that.

So the use of JForms in that case is quite different.

For exemple, to avoid data overlap between several windows/tabs, you may want to clear() a jForm after making a fill() (if entered data is not accepted by your app). Destroy() only decrements the counter. You may want to destroy all instances, so add a destroyAllInstances(). You may also want to know how many instances of a form where created with getInstancesCount().

There is also a clean() method which exists but is not documented, as far as I know.

With those 3 additional methods, you could use jForms as is :

  • prepare : create() a jForms, whatever get() is (you may test getInstancesCount() if you want to avoid to many creations). Multiple create() on a given selector won't bloat $_SESSION since it just increments a counter. You may clean() before create() to remove old instances.
  • show : if you need to, setData() to some fields, fetch() your template assigning him the form and then clear() the form. This prevents multiple jForms data overlap
  • save : fill() your form. If there are data errors, clear() it and redirect to show(). If everything is OK, store your data or whatever you have to do with them, clear() your jForms and go to "end"
  • end : destroy() your jForms

In some place of your code, for example when a user connects, you can call destroyAllInstances() - with no args - to make sure all instances of all forms are destroyed.

Change History (3)

Changed 12 years ago by bricet

Patch to introduced 3 new methods

comment:1 Changed 11 years ago by laurentj

  • Milestone set to Jelix 1.2

comment:2 Changed 11 years ago by laurentj

  • Description modified (diff)
  • Milestone Jelix 1.2 deleted

you may want to clear() a jForm after making a fill() (if entered data is not accepted by your app).

Why doing a clear ? If you clear the form when there is an error, so the user loose all values he typed. Not very cool.

And I don't see when data are overlaped, with or without clear(). Because on each tab, when you submit, then you call fill(), and fill() overwrite data in the container in the session. So, what is the problem ?

destroyAllInstances(): why not..

getInstancesCount(): why not, but I think it is useless. jForms is designed to not manage ourselves instances... So what is the use case of this method ? Give me an example please.

Note: See TracTickets for help on using tickets.