Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get red borders when a field is invalid using WTForms with GAE and Jinja2?
    primarykey
    data
    text
    <p>I've got validation practically working and part of my requirement is that when a field is not valid there should be a red border around the field that is not valid:</p> <p><img src="https://i.stack.imgur.com/1i7v6.png" alt="enter image description here"></p> <pre><code>&lt;tr&gt;&lt;td valign="top"&gt; &lt;div class="labelform" id="lname"&gt; {% filter capitalize %}{% trans %}name{% endtrans %}{% endfilter %}: &lt;/div&gt;&lt;/td&gt;&lt;td&gt; &lt;div class="adinput"&gt; {% if user or current_user %} &lt;input type="text" id="name" name="name" value="{{ current_user.name }}{% if not current_user %}{{ user.nickname() }}{% endif %}" size="35" maxlength="50" readonly/&gt; {% else %} {{ form.name|safe }} {% endif %} {% if form.name.errors %} &lt;ul class="errors"&gt;{% for error in form.name.errors %}&lt;li&gt;{{ error }}&lt;/li&gt;{% endfor %}&lt;/ul&gt; {% endif %} &lt;/div&gt; &lt;/td&gt;&lt;/tr&gt; </code></pre> <p>Can you tell me how I should achieve the red border around the form field conditioned on that the name field is not valid? Here's my python code for my form class:</p> <pre><code>class AdForm(Form): name = TextField(_('Name'), [validators.Length(min=4, max=50, message=_('Name is required'))]) title = TextField(_('title')) text = TextAreaField(_('Text'), widget=TextArea()) phonenumber = TextField(_('Phone number')) phoneview = BooleanField(_('Display phone number on site')) price = TextField(_('Price')) password = PasswordField(_('Password')) email = TextField(_('Email')) </code></pre> <p>The code that handles the HTTP POST of the form is:</p> <pre><code>... form = AdForm(self.request.params) if form.validate(): ad.title = form.title.data ad.name = form.name.data ad.email = form.email.data ad.text = form.text.data ad.set_password(form.password.data) ad.price = form.price.data try: form.price.data=form.price.data.replace(',','.').replace(' ', '') ad.decimal_price = form.price.data except: pass ad.phoneview = form.phoneview.data ad.url = os.environ.get('HTTP_HOST', os.environ['SERVER_NAME']) ad.place = self.request.get('place') ad.postaladress = self.request.get('place') ad.put() else: logging.info('form did not validate') self.render_jinja( 'insert_jinja', facebook_app_id=facebookconf.FACEBOOK_APP_ID, form=form, form_url=blobstore.create_upload_url('/upload_form'), user=(users.get_current_user() if users.get_current_user() else None), user_url=(users.create_logout_url(self.request.uri) if users.get_current_user() else None), current_user=self.current_user, ) return ... </code></pre> <p>Can you tell me how I should get the red border when a field is invalid? </p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload