views:

19

answers:

0

Does anyone have any tips for creating versatile Javascript widgets that can be used both in a 'new record' form for POSTing, and in an 'edit record' page with instance AJAX updates. For example, a map that can operate in these two modes:

  • create record: markers are added, and included in the form when it is POSTed
  • edit record: as each marker is added, an AJAX request is sent and that marker is immediately added to the record

I'm using jQuery, and my current thinking is to have the widget just raise custom events, which are bound to by either a "add to hidden form field" function or a "send AJAX request" function. I'd like to avoid as much duplication as possible, as I have a few custom widgets to write.