Re: Executing form callbacks within a block
Esteban Maringolo <[email protected]> Thu, 20 May 2021 11:10:12 -0300
| Newsgroups | gmane.comp.lang.smalltalk.squeak.seaside |
|---|---|
| Message-ID | <CAJMgPCJZLeuPrWHbWuUyBkjUNx_6GMp8FMvaa-TwLCCZF_=9LA@mail.gmail.com> |
Well.. I'm not writing the values directly to the database, but I'm using GLORP in between. Glorp detects changes and at the end of a "unit of work" (kinda transaction) it creates the corresponding statements to write/update/delete rows in the database. But in order to do that it has to know the object "state" before starting doing mutations on it. So what I finally did was to have a hidden input as the first callback. A super simplified version, without validations and whatnot is like this: html form: [ html hiddenInput callback: [self db beginUnitOrWork. self db register: self model]. html textInput on: #name of: self model. html submitButton callback: [self db commitUnitOfWork] ] Regards! Esteban A. Maringolo On Wed, May 19, 2021 at 10:59 PM Jupiter Jones <[email protected]> wrote: > > To be clearer… :) > > No callback on the submit button. > > html form callback: [ > self beginTransaction. > “Update database from #name and #age fields” > self commitTransaction > ] > > > On 20 May 2021, at 11:55 am, Jupiter Jones <[email protected]> wrote: > > > > It’s been a while since I’ve done this, but if you have a callback on the form itself, which handles validation and if valid, starts a transaction, moves the data from the temporary variables used by the web form to the database, then commits. > > > > I’m guessing from the question that you may have bound your inputs directly to database objects that will revert their value when you beginTransaction? > > > >> On 20 May 2021, at 11:18 am, Esteban Maringolo <[email protected]> wrote: > >> > >> Hi all, > >> > >> I have a situation where I want to execute _ALL_ the callbacks of the > >> inputs in the form within a particular block (basically, a DB > >> transaction). > >> > >> html form: [ > >> html textInput on: #name of: self. > >> html textInput on: #age of: self. > >> html submitButton > >> ] > >> > >> I want to execute the three callbacks within something else, or at > >> least have the option to execute something before the first callback > >> executes and ensure something gets executed after the last one is > >> executed. > >> > >> I know it involves fiddling somehow with > >> WACallbackProcessingActionContinuation, but it's not fully clear if I > >> could do this. > >> > >> The hacky alternative would be to have a hidden field that does start > >> the tx and the submit / cancel commits or cancels it. > >> > >> html form: [ > >> html hiddenInput callback: [self beginTransaction]. > >> html textInput on: #name of: self. > >> html textInput on: #age of: self. > >> html submitButton > >> callback: [self commitTransaction]; > >> value: 'Submit'. > >> ] > >> > >> But in this case I'd have to keep the tx "outside" of the form, and > >> I'd like to wrap everything in a single block. > >> > >> Is there a way to do this with Seaside? > >> > >> Thanks! > >> > >> Esteban A. Maringolo > >> _______________________________________________ > >> seaside mailing list > >> [email protected] > >> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside > > > _______________________________________________ seaside mailing list [email protected] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside