Ticket #5775 (closed defect: worksforme)

Opened 6 months ago

Last modified 4 months ago

Broken Backwards compatibility for dijit.form.Form

Reported by: nathan Owned by: doughays
Priority: normal Milestone: 1.1
Component: Dijit Version: 1.0
Severity: normal Keywords:
Cc:

Description

In the latest code from svn, it appears that dijit.form.Form's execute method is deprecated. That's fine, but if I want to use a dijit.form.Form as a subwidget of another widget, how can I tie in to the submit event?

What worked previously in a templateString: <form dojoType="dijit.form.Form" dojoAttachEvent="execute:_processForm">

I tried setting dojoAttachEvent="onSubmit:_myFunc" and dojoAttachEvent="submit:_myFunc" - but neither of them have a way of "cancelling" the event from firing (the form still gets submitted). Tying in to execute previously (in 1.0.2) would attach me when the form was submitted (by pressing <enter> or by clicking a submit button).

Maybe a good compromise would be to offer an option on dijit.form.Form - so that you can do something like this: <form dojoType="dijit.form.Form" dojoAttachEvent="onSubmit:_processForm" doSubmit="false">

doSubmit would default to true - but the onSubmit() function for dijit.form.Form would then return (this.isValid() && this.doSubmit) instead of just this.isValid()

Change History

Changed 6 months ago by bill

  • cc nathan@… removed
  • owner changed from anonymous to doughays
  • reporter changed from guest to nathan@toonetown.com
  • component changed from General to Dijit
  • milestone set to 1.1

Hmm, I thought the submit would be canceled just by returning false from that onSubmit override. Doug?

Changed 6 months ago by guest

If you override, yes, it does cancel - but returning false from it when it's *connected* doesn't seem to...

Changed 5 months ago by bill

Oh, right, that's the way connections work regardless of what function you are connecting to. The return value from a connection is ignored. You need to override the function.

I see how that's difficult when using Form as a subwidget in a template for another widget though. Hmm. I guess that's a general limitation of the widgetsInTemplate feature that should be addressed at some point.

One option is to declare your own widget. Note how Dialog doesn't extend Form, but rather just uses _FormMixin:

dojo.declare(
	"dijit.Dialog",
	[dijit.layout.ContentPane, dijit._Templated, dijit.form._FormMixin, dijit._DialogMixin],

Anyway, leaving open to discuss with Doug.

Changed 5 months ago by bill

Doug just pointed out to me that you could just *add* onSubmit="return false;" to your template, like:

<form dojoType="dijit.form.Form" onSubmit="return false;" dojoAttachEvent="execute:_processForm">

You could connect to onSubmit rather than execute (since execute() is deprecated) but the only problem is that onSubmit() isn't passed the form values, so you have to call this.getValues() inside of your function.

I guess this is a break in backwards compatibility from the perspective of widgetsInTemplate, but from the common use case of using a Form widget as an actual form on a page, it's more like a bug fix, so that's why we changed it for 1.1.

Does that work for you?

Changed 5 months ago by doughays

  • status changed from new to closed
  • resolution set to worksforme

Confirmed with Nathan that this issue has been resolved.

Changed 5 months ago by nathan

  • reporter changed from nathan@toonetown.com to nathan

Changed 4 months ago by guest

I have fixed my forms , simulating the old execute method by

<form dojoType="dijit.form.Form" id="sequence_filtering">
{literal}
<script type="dojo/method" event="onSubmit" args="evt">
dojo.stopEvent(evt);
//do your processing

Note: See TracTickets for help on using tickets.