This is duplicated from saved-search-edit.js. Refactoring these so the functions can be shared will prevent edit problems in the future.