Zend_Form + JQuery + tabs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Form + JQuery + tabs

David Mintz-3
Embarking on my first ajaxified Zend Form with a JQuery UI-tabbed interface, I am wondering what sort of practices people recommend.

Say we have tabs 1, 2 and 3, left to right. Tab 1 is displayed first. They click tab 2. We use a JQuery tabsselect callback to submit only the data from tab 1 for validation. So... in the controller I presume we should call $form->processAjax(...) to validate the $_POSTed data, yes?

Back to the client side, the JQuery callback displays errors and returns false if there are any errors, otherwise true and the next tab is displayed. Right?

When they finally click the submit button, do we xhr-submit all the data from all the tabs and fields, and validate it all once again? It seems redundant if you do, but risky if you don't.

OTOH, with each click on the next tab, you could actually save the successfully validated data from the current tab (in this case, in a database) and carry on. That would obviate the need for re-validating. Then again, as a user I don't expect to save until I actually click a submit button rather than a tab.

Comments?

--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form + JQuery + tabs

scss
Hi,
I would validate each step's data and save it in session.
However, if any previous tab is clicked and there was an attempt to
change any validated input,
then I would validate that input again.

In other words,
click 2nd tab->validate 1st tab data and save in session.
click 3rd tab->validate 2nd tab data and save in session
click submit button -> validate 3rd tab data and insert the
session-saved+3rd tab's validated data in db (or any operation else)
if any previous/validated tab clicked and information is changed on
that tab (before the submit is clicked), re-validate that data again.
I do not think there is a need to re-submit all tabs' data again once
the submit button is clicked.

scs



On Fri, Mar 12, 2010 at 8:04 PM, David Mintz <[hidden email]> wrote:

> Embarking on my first ajaxified Zend Form with a JQuery UI-tabbed interface,
> I am wondering what sort of practices people recommend.
>
> Say we have tabs 1, 2 and 3, left to right. Tab 1 is displayed first. They
> click tab 2. We use a JQuery tabsselect callback to submit only the data
> from tab 1 for validation. So... in the controller I presume we should call
> $form->processAjax(...) to validate the $_POSTed data, yes?
>
> Back to the client side, the JQuery callback displays errors and returns
> false if there are any errors, otherwise true and the next tab is displayed.
> Right?
>
> When they finally click the submit button, do we xhr-submit all the data
> from all the tabs and fields, and validate it all once again? It seems
> redundant if you do, but risky if you don't.
>
> OTOH, with each click on the next tab, you could actually save the
> successfully validated data from the current tab (in this case, in a
> database) and carry on. That would obviate the need for re-validating. Then
> again, as a user I don't expect to save until I actually click a submit
> button rather than a tab.
>
> Comments?
>
> --
> Support real health care reform:
> http://phimg.org/
>
> --
> David Mintz
> http://davidmintz.org/
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form + JQuery + tabs

David Mintz-3


On Fri, Mar 12, 2010 at 1:34 PM, scs <[hidden email]> wrote:
Hi,
I would validate each step's data and save it in session.
However, if any previous tab is clicked and there was an attempt to
change any validated input,
then I would validate that input again.

In other words,
click 2nd tab->validate 1st tab data and save in session.
click 3rd tab->validate 2nd tab data and save in session
click submit button -> validate 3rd tab data and insert the
session-saved+3rd tab's validated data in db (or any operation else)
if any previous/validated tab clicked and information is changed on
that tab (before the submit is clicked), re-validate that data again.
I do not think there is a need to re-submit all tabs' data again once
the submit button is clicked.

So it doesn't make it into the session unless it's valid. This sounds like a good approach.

Question: how do we detect whether they have changed data in a previously-validated tab? Compare POSTed data to what's in the session, obviously. But how expensive is that compared to validating again unconditionally? Especially considering that if it's changed we will definitely validate again anyway.


--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/


Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form + JQuery + tabs

Mike Wright
David Mintz wrote:

> On Fri, Mar 12, 2010 at 1:34 PM, scs <[hidden email]> wrote:
>
>> Hi,
>> I would validate each step's data and save it in session.
>> However, if any previous tab is clicked and there was an attempt to
>> change any validated input,
>> then I would validate that input again.
>>
>> In other words,
>> click 2nd tab->validate 1st tab data and save in session.
>> click 3rd tab->validate 2nd tab data and save in session
>> click submit button -> validate 3rd tab data and insert the
>> session-saved+3rd tab's validated data in db (or any operation else)
>> if any previous/validated tab clicked and information is changed on
>> that tab (before the submit is clicked), re-validate that data again.
>> I do not think there is a need to re-submit all tabs' data again once
>> the submit button is clicked.
>>
>
> So it doesn't make it into the session unless it's valid. This sounds like a
> good approach.
>
> Question: how do we detect whether they have changed data in a
> previously-validated tab? Compare POSTed data to what's in the session,
> obviously. But how expensive is that compared to validating again
> unconditionally? Especially considering that if it's changed we will
> definitely validate again anyway.

Doesn't all of this become irrelevant if the current subForm is
validated and stored on any submission?  After that your model/flow can
decide which subForm should be presented next.  That makes possible
previous/next and buttons to arbitrarily select the order of the forms
(after all, the user should be able to determine their own workflow, no?).

.02 US (not worth much before, a lot less now)
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Form + JQuery + tabs

David Mintz


On Fri, Mar 12, 2010 at 4:45 PM, Mike Wright <[hidden email]> wrote:
David Mintz wrote:
On Fri, Mar 12, 2010 at 1:34 PM, scs <[hidden email]> wrote:

Hi,
I would validate each step's data and save it in session.
However, if any previous tab is clicked and there was an attempt to
change any validated input,
then I would validate that input again.

In other words,
click 2nd tab->validate 1st tab data and save in session.
click 3rd tab->validate 2nd tab data and save in session
click submit button -> validate 3rd tab data and insert the
session-saved+3rd tab's validated data in db (or any operation else)
if any previous/validated tab clicked and information is changed on
that tab (before the submit is clicked), re-validate that data again.
I do not think there is a need to re-submit all tabs' data again once
the submit button is clicked.


So it doesn't make it into the session unless it's valid. This sounds like a
good approach.

Question: how do we detect whether they have changed data in a
previously-validated tab? Compare POSTed data to what's in the session,
obviously. But how expensive is that compared to validating again
unconditionally? Especially considering that if it's changed we will
definitely validate again anyway.

Doesn't all of this become irrelevant if the current subForm is validated and stored on any submission?  After that your model/flow can decide which subForm should be presented next.  That makes possible previous/next and buttons to arbitrarily select the order of the forms (after all, the user should be able to determine their own workflow, no?).

.02 US (not worth much before, a lot less now)

Maybe I'm not getting your point.

I don't plan to have subforms correspond to tabs one-for-one, because there are multiple models, each with a corresponding subform. I just want to split up groups of fields into tabs for the sake of presentation; there's a single submit button for all. When they move from tab to tab they aren't going to be submitting, but it seems a fine opportunity to processAjax() and validate the current section of the form before it gets hidden from view.

--
Support real health care reform:
http://phimg.org/

--
David Mintz
http://davidmintz.org/