Apply new form validation features to New Post form

- Use TextAreaField instead of StringField on forms.NewPostForm
- Fixed incorrect remember_me field and redirect in login
- Added placeholder usage to field rendering macro
This commit is contained in:
Xevion
2022-03-29 15:13:00 -05:00
parent 8cf2f02772
commit f41b83a15f
10 changed files with 47 additions and 46 deletions
+5 -3
View File
@@ -1,6 +1,8 @@
{% macro render_field(field) %}
{{ field.label }}
{{ field(**kwargs)|safe }}
{% macro render_field(field, show_label=True) %}
{% if show_label %}
{{ field.label }}
{% endif %}
{{ field(placeholder=field.description, **kwargs)|safe }}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
+6 -13
View File
@@ -1,23 +1,16 @@
{% extends 'layouts/index.html' %}
{% from 'macros.html' import render_field %}
{% block content %}
{% if current_user.is_authenticated %}
{% with messages = get_flashed_messages() %}
{% if messages or true %}
<span class="error-message center-message">
{{ messages[0] }}
</span>
{% endif %}
{% endwith %}
<form method="POST" action="{{ url_for('forms.new_post') }}" class="profile-form">
<label>
<textarea type="text" name="text" placeholder="Write a post between 15 and 1000 characters. Express yourself."></textarea>
</label>
<button class="button">Create Post</button>
<form method="POST" class="form post-form">
{{ render_field(form.text, show_label=False) }}
<input type=submit value="Create Post">
</form>
{% endif %}
<hr style="margin: 2em 0">
{% for post, author in posts_and_authors %}
<div class="post-box">
{{ post.text }}
+1 -1
View File
@@ -2,7 +2,7 @@
{% block content %}
<h3>Edit Profile</h3>
<form method="POST" action="{{ url_for('forms.edit_profile_post', username=user.username) }}" class="profile-form">
<form method="POST" action="{{ url_for('forms.edit_profile_post', username=user.username) }}" class="form">
<label>
Name<br>
<input type="text" name="name" value="{{ user.name }}">