Commits

Luke Plant committed fb459dc

Made copying of data on 'add place' page behave more nicely with validation errors

Comments (0)

Files changed (2)

cciw/cciwmain/static/js/cciwutils.js

                                         });
     };
 
+    pub.standardformClearError = standardformClearError;
+
     $(document).ready(function() {
         $('form.ajaxify').each(function(i, elem) {
             pub.standardformAddOnchangeHandlers($(this));

templates/cciw/bookings/add_place.html

                        } else {
                            mainform[attr].value = place[attr];
                        }
+                       // If details are copied from something saved,
+                       // value is guaranteed to be good. So we clear
+                       // errors.
+                       cciw.standardformClearError(mainform[attr].id)
                    }
                }
            }
            useData(gp_info_attrs);
        };
 
+       var useAccountData = function(nameList, prefix) {
+           // exploit the fact that we've named things nicely.
+           $.each(nameList, function(idx, val) {
+               $('#id_' + prefix + val).val(userData['account'][val]);
+               cciw.standardformClearError('id_' + prefix + val);
+           });
+       };
+
        var useAccountForCamperAddressClick = function(ev) {
            ev.preventDefault();
-           $('#id_address').val(userData['account']['address']);
-           $('#id_post_code').val(userData['account']['post_code']);
-           $('#id_phone_number').val(userData['account']['phone_number']);
-       }
+           useAccountData(['address', 'post_code', 'phone_number'], '');
+       };
 
        var useAccountForContactDetailsClick = function(ev) {
            ev.preventDefault();
-           $('#id_contact_name').val(userData['account']['name']);
-           $('#id_contact_phone_number').val(userData['account']['phone_number']);
-       }
+           // copy contact_name, contact_phone_number
+           useAccountData(['name', 'phone_number'], 'contact_');
+       };
 
        $('#id_popup_close_btn').click(useExistingDataClose);
        $('#id_use_existing_btn').click(useExistingDataShow);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.