Commits

Anonymous committed 97f2e86

0.12.2dev: In preference panels, only wrap a panel in a `<form>` and add a "Save changes" button if the panel doesn't contain any forms itself. This allows using more than one form e.g. in the "Advanced" panel, and fixes an issue where pressing ENTER in the "Session key" edit box would trigger restoring a session instead of changing the session ID.

Part of #9658.

Comments (0)

Files changed (3)

trac/prefs/templates/prefs.html

     ${select("*[local-name() != 'title']")}
   </head></py:match>
 
-  <py:match path="body" once="true" buffer="false"><body>
+  <py:match path="body" once="true" buffer="true"><body>
     <div id="content" class="prefs">
       <h1>Preferences</h1>
       <p>This page lets you customize your personal settings for this site.
           <a py:strip="name == active_panel" href="${href.prefs(name)}">${label}</a>
         </li>
       </ul>
-      <div id="tabcontent">
-        <form id="userprefs" action="" method="post">
+      <div id="tabcontent" py:with="has_forms = list(select('.//form'))">
+        <form id="userprefs" action="" method="post" py:strip="has_forms">
           ${select("*|text()")}
-          <div class="buttons">
+          <div class="buttons" py:if="not has_forms">
             <input type="hidden" name="action" value="save" />
             <input type="submit" value="${_('Save changes')}" />
           </div >

trac/prefs/templates/prefs_advanced.html

   </head>
   <body>
 
-    <div class="field">
+    <div class="field"><form action="" method="post">
       <label>Session key:
-        <input type="text" name="newsid" size="30"
-               value="${settings.session_id}" />
+        <input type="text" name="newsid" size="30" value="${settings.session_id}" />
       </label>
+      <input type="submit" name="change" value="${_('Change')}" />
       <p class="hint">The session key is used to identify stored custom
       settings and session data on the server. Although it is
       automatically generated by default, you may change it to something
       easier to remember at any time if you wish to load your settings
       in a different web browser.</p>
-    </div>
+    </form></div>
 
-    <div class="field">
+    <div class="field"><form action="" method="post">
       <label>Restore session:
         <input type="text" name="loadsid" size="30" value="" />
       </label>
       <p class="hint">You may load a previously created session by entering the
       corresponding session key below. This lets you share settings between
       multiple computers and web browsers.</p>
-    </div>
+    </form></div>
 
   </body>
 </html>

trac/prefs/web_ui.py

     def _do_load(self, req):
         if req.authname == 'anonymous':
             oldsid = req.args.get('loadsid')
-            req.session.get_session(oldsid)
+            if oldsid:
+                req.session.get_session(oldsid)
+                add_notice(req, _('The session has been loaded.'))