PDA

View Full Version : Error Handling - Forms


thegladio
10-13-2004, 01:21 AM
I have seen in one of the other threads the Email example (posted by Autun I think). It is pasted in below. It is a very helpful example but I am still confused about how to go about handling errors generated by the application and informing the user. For example, either validation errors or business logic related errors.

In paticular, I am unsure about how the onerror event works. How can my application trigger the datapointer's onerror event? Is there someplace in the tutorial or other docs which explains this? (I haven't been able to find it yet)


<canvas>

<!-- Dataset to make the HTTP POST request and receive any
XML that was returned -->
<dataset name="msg_ds" type="http"
src="http://localhost/form_submission/doSubmit.asp"
request="false" />

<!-- Datapointer that is triggered by the response -->
<datapointer name="msg_dp" xpath="msg_ds:/response">
<method event="ondata">
mydialog.txt.setText(this.xpathQuery("@msg"));
</method>
<method event="onerror">
mydialog.txt.setText("Error!");
</method>
<method event="ontimeout">
mydialog.txt.setText("Timeout!");
</method>
</datapointer>


<!-- Dialog box -->
<modaldialog name="mydialog" width="300" height="200">
<text name="txt" width="160" align="center" multiline="true" />
<view align="right" layout="axis:x; spacing:20">
<button onclick="parent.parent.close()"
isdefault="true">OK</button>
</view>
<simplelayout spacing="5"/>
</modaldialog>


<!-- Form fields -->
<window title="Compose Message" width="200" height="320"
x="30" y="20">
<simplelayout axis="y" spacing="5" />
<text>To (email):</text>
<edittext name="toEmail" width="160" />
<text>Subject:</text>
<edittext name="subject" width="160" />
<text>Message:</text>
<edittext name="message" width="160" height="100" multiline="true"/>
<button>Send message!
<method event="onclick">
msg_ds.setQueryType("POST");
msg_ds.setQueryParams( { to:parent.toEmail.text,
subject:parent.subject.text,
message:parent.message.text } );
msg_ds.doRequest();
mydialog.open();
mydialog.txt.setText("Sending...");
</method>
</button>
</window>
</canvas>

antun
10-14-2004, 01:59 PM
In paticular, I am unsure about how the onerror event works. How can my application trigger the datapointer's onerror event?

The onerror event is for server errors - you don't send it programatically. You should listen for it in case there's a problem with the response though.

Validation is up to you - you could write a class that highlighted a form field that had missing information, or you could change the font color, etc.

-Antun