No new skills in this section: picking up on what you learned in the final webforms intro tutorial, you'll be getting better at writing validation
controls and server-side scripts to process webform data submissions.
Adding validation to the user-editable controls
Whenever you allow users to update records in an existing reference table
(assignments
in this case), it's always a good idea to make sure that the
changes are consistent with the declaration for the reference table. You do this, as
you very well know, by validating the form data before the form is submitted, at the
latest.
The validation that you need to add to the controls in the taskEditor
table is basically the same as the ones you put into the newTask webform.
<table id='taskEditor' ... <cell> <dropdown id='editedDriver' choices='{SELECT u.userid, u.name FROM drivers u}' keyMap='{userid}' textMap='{name}' selectedKey='{edit.userid}'><validation> <validator cond='{selectedKey is not null}' message="Required field"/> </validation>
</dropdown> </cell> <cell> <dropdown id='editedLoad' choices='{SELECT c.cargo_type FROM cargoTypes c}' keyMap='{cargo_type}' textMap='{cargo_type}' selectedKey='{edit.load_type}'><validation> <validator cond='{selectedKey is not null}' message="Required field"/> </validation>
</dropdown> </cell> <cell> <dropdown id='editedClient' choices='{SELECT c.client_name FROM clients c}' keyMap='{client_name}' textMap='{client_name}' selectedKey='{edit.client}'><validation> <validator cond='{selectedKey is not null}' message="Required field"/> </validation>
</dropdown> </cell> <cell> <textbox id='editedLoadAddress' text='{edit.load_address}'><validation> <validator cond='{text != ""}' message="Required field"/> </validation>
</textbox> </cell> <cell> <textbox id='editedDeliveryAddress' text='{edit.unload_address}'><validation> <validator cond='{text != ""}' message="Required field"/> </validation>
</textbox> </cell> <cell> <datepicker id='editedDueDate' dateFormat='(dtf yyyy"/"MM"/"dd)' date='{edit.due_date}'><validation> <validator cond='{date is not null}' message="Required field"/> <validator cond='{date >= sysp.dtlFormOpen}' message="Due date cannot be earlier than current date."/> </validation>
</datepicker> </cell> <cell> <dropdown id='editedStatus' choices='{SELECT s.status FROM statusVar s}' keyMap='{status}' textMap='{status}' selectedKey='{edit.status}'><validation> <validator cond='{selectedKey is not null}' message="Required field"/> </validation>
</dropdown> </cell> <cell> <removebutton text="Cancel edit" /> </cell> </row> </table>
Save, publish, and view the form online.
Move a few entries down into the editing part of the form, and willfully violate the validation conditions. You rebel, you.
If you've got everything right in the code, the validation messages will show up even before you try to submit the form with the bad input.
Sweet. Your form is officially finished. Time to make it do what it says it does, that
is, edit the reference table.-
Updating the reference table based on user input in the form
Now that the Rocky Jupiter Deliveries webform has all its gears in
order, and even has a few bells and whistles, you can write the workflow script that will
take everything inside the taskEditor
table control, and overwrite the
assignments
reference table with the values in its rows.
Create a new file in your text editor, paste the code below into it, and save it as
taskUpdater.rfs
in your solution artifacts
folder.
server program taskUpdater for form list using reftab assignments; { foreach(var row in form.taskEditor.rows) db.assignments.Update({assignment_id:row.assignment_id}, {usr:row.editedDriver.selectedKey, client:row.editedClient.selectedKey, load_type: row.editedLoad.selectedKey, load_address:row.editedLoadAddress.text, unload_address:row.editedDeliveryAddress.text, due_date:row.editedDueDate.date.DtlToDtdb(), status:row.editedStatus.selectedKey}); }
Publish your webforms
artifacts folder that now has
taskUpdater
inside it, open the webform, and make a change to
one of the delivery entries. Move into the Backoffice site, and check that the
workflow script has run successfully.
If it has, export the current assignments
reference table,
and check that the change that you made shows up.
Welcome to the end of the webforms tutorial.
You now know all about all the ins and outs of data-binding in webforms, dynamic filtering, setting up variables.
Even query statements that should switch between running on the server and in the browser cannot trip you up. Not too shabby.