changeset 214:0f501a426b50

HTML5 <input> Tag attribute "required" added additional to the required class definition. This indicates that the input field's value is required in order to submit the form. On HTML5 capable browsers the form is not send until the value is set.
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 04 May 2011 22:22:46 +0200
parents 1c835a7297ea
children d661d49a46dc
files MoinMoin/templates/forms.html MoinMoin/templates/login.html MoinMoin/templates/openid_register.html MoinMoin/templates/recoverpass.html MoinMoin/templates/register.html
diffstat 5 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/templates/forms.html	Wed May 04 01:32:54 2011 +0200
+++ b/MoinMoin/templates/forms.html	Wed May 04 22:22:46 2011 +0200
@@ -15,13 +15,16 @@
   {% endif %}
 {% endmacro %}
 
-{% macro render_field(gen, field, field_type) %}
-  {% set f_class = "optional" if field.optional else "required" %}
+{% macro render_field(gen, field, field_type, class="optional") %}
   <dt>
-    {{ gen.label(field, class=f_class) }}
+    {{ gen.label(field, class=class) }}
   </dt>
   <dd>
-    {{ gen.input(field, class=f_class, type=field_type) }}
+    {% if class == "optional" %}
+      {{ gen.input(field, class="optional", type=field_type) }}
+    {% else %}
+      {{ gen.input(field, class="required", type=field_type, required="required") }}
+    {% endif %}
     {{ render_errors(field) }}
   </dd>
 {% endmacro %}
@@ -50,7 +53,7 @@
         {# The value of -51 below is the sum of signature length, timestamp and a space (see security/textcha.py) #}
         {{ form.textcha_question.value[:-51] }}
         {{ gen.input(form.textcha_question, class=f_class, type='hidden') }}<br />
-        {{ gen.input(form.textcha, class="required") }}
+        {{ gen.input(form.textcha, class="required", required="required") }}
         {{ render_errors(form.textcha) }}
     </dd>
     {% endif %}
--- a/MoinMoin/templates/login.html	Wed May 04 01:32:54 2011 +0200
+++ b/MoinMoin/templates/login.html	Wed May 04 22:22:46 2011 +0200
@@ -12,10 +12,10 @@
   {{ gen.input(form['submit'], type='hidden') }}
 
   {% if 'username' in login_inputs %}
-  {{ forms.render_field(gen, form['username'], 'text') }}
+  {{ forms.render_field(gen, form['username'], 'text', 'required') }}
   {% endif %}
   {% if 'password' in login_inputs %}
-  {{ forms.render_field(gen, form['password'], 'password') }}
+  {{ forms.render_field(gen, form['password'], 'password', 'required') }}
   {% endif %}
 
   <input type="submit" value="{{ _('Log in') }}" />
--- a/MoinMoin/templates/openid_register.html	Wed May 04 01:32:54 2011 +0200
+++ b/MoinMoin/templates/openid_register.html	Wed May 04 22:22:46 2011 +0200
@@ -12,10 +12,10 @@
     <dt>{{ gen.label(form['openid']) }}</dt>
     <dd>{{ gen.input(form['openid'], type='text', readonly='1') }}</dd>
 
-    {{ forms.render_field(gen, form['username'], 'text') }}
-    {{ forms.render_field(gen, form['password1'], 'password') }}
-    {{ forms.render_field(gen, form['password2'], 'password') }}
-    {{ forms.render_field(gen, form['email'], 'text') }}
+    {{ forms.render_field(gen, form['username'], 'text', 'required') }}
+    {{ forms.render_field(gen, form['password1'], 'password', 'required') }}
+    {{ forms.render_field(gen, form['password2'], 'password', 'required') }}
+    {{ forms.render_field(gen, form['email'], 'text', 'required') }}
     {{ forms.render_textcha(gen, form) }}
   </dl>
   <input type="submit" value="{{ _("Register") }}" />
--- a/MoinMoin/templates/recoverpass.html	Wed May 04 01:32:54 2011 +0200
+++ b/MoinMoin/templates/recoverpass.html	Wed May 04 22:22:46 2011 +0200
@@ -6,10 +6,10 @@
 {{ gen.form.open(form, method="post", action=url_for('frontend.recoverpass')) }}
   {{ forms.render_errors(form) }}
   <dl>
-    {{ forms.render_field(gen, form['username'], 'text') }}
-    {{ forms.render_field(gen, form['token'], 'text') }}
-    {{ forms.render_field(gen, form['password1'], 'password') }}
-    {{ forms.render_field(gen, form['password2'], 'password') }}
+    {{ forms.render_field(gen, form['username'], 'text', 'required') }}
+    {{ forms.render_field(gen, form['token'], 'text', 'required') }}
+    {{ forms.render_field(gen, form['password1'], 'password', 'required') }}
+    {{ forms.render_field(gen, form['password2'], 'password', 'required') }}
   </dl>
   {{ gen.input(form['submit'], type='submit') }}
 {{ gen.form.close() }}
--- a/MoinMoin/templates/register.html	Wed May 04 01:32:54 2011 +0200
+++ b/MoinMoin/templates/register.html	Wed May 04 22:22:46 2011 +0200
@@ -7,10 +7,10 @@
 {{ gen.form.open(form, method="post", action=url_for('frontend.register')) }}
   {{ forms.render_errors(form) }}
   <dl>
-    {{ forms.render_field(gen, form['username'], 'text') }}
-    {{ forms.render_field(gen, form['password1'], 'password') }}
-    {{ forms.render_field(gen, form['password2'], 'password') }}
-    {{ forms.render_field(gen, form['email'], 'text') }}
+    {{ forms.render_field(gen, form['username'], 'text', 'required') }}
+    {{ forms.render_field(gen, form['password1'], 'password', 'required') }}
+    {{ forms.render_field(gen, form['password2'], 'password', 'required') }}
+    {{ forms.render_field(gen, form['email'], 'text', 'required') }}
     {{ forms.render_field(gen, form['openid'], 'text') }}
     {{ forms.render_textcha(gen, form) }}
   </dl>