updated with covers and authors
parent
9461301d21
commit
7e1c504e09
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,21 @@
|
|||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import StringField, FileField
|
from wtforms import StringField, FileField
|
||||||
from wtforms.validators import InputRequired
|
from wtforms.validators import InputRequired, DataRequired
|
||||||
|
from wtforms import FieldList
|
||||||
|
from wtforms import Form as NoCsrfForm
|
||||||
|
from wtforms.fields import StringField, FormField, SubmitField
|
||||||
|
from app.models import Book, BookSchema, Author
|
||||||
|
|
||||||
|
# - - - Forms - - -
|
||||||
|
class AuthorForm(NoCsrfForm):
|
||||||
|
# this forms is never exposed so we can user the non CSRF version
|
||||||
|
author_name = StringField('Author Name', validators=[DataRequired()])
|
||||||
|
|
||||||
class UserForm(FlaskForm):
|
class UserForm(FlaskForm):
|
||||||
title = StringField('title', validators=[InputRequired()])
|
title = StringField('title', validators=[InputRequired()])
|
||||||
author = StringField('author', validators=[InputRequired()])
|
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
|
||||||
file = FileField()
|
file = FileField()
|
||||||
|
|
||||||
|
class UserForm_Edit(FlaskForm):
|
||||||
|
title = StringField('title', validators=[InputRequired()])
|
||||||
|
author = FieldList(FormField(AuthorForm, default=lambda: Author()), min_entries=1)
|
||||||
|
@ -1 +1,32 @@
|
|||||||
/* Add your Application JavaScript */
|
/* Add your Application JavaScript */
|
||||||
|
$(function() {
|
||||||
|
$("div[data-toggle=fieldset]").each(function() {
|
||||||
|
var $this = $(this);
|
||||||
|
|
||||||
|
//Add new entry
|
||||||
|
$this.find("button[data-toggle=fieldset-add-row]").click(function() {
|
||||||
|
var target = $($(this).data("target"))
|
||||||
|
console.log(target);
|
||||||
|
var oldrow = target.find("[data-toggle=fieldset-entry]:last");
|
||||||
|
var row = oldrow.clone(true, true);
|
||||||
|
console.log(row.find(":input")[0]);
|
||||||
|
var elem_id = row.find(":input")[0].id;
|
||||||
|
var elem_num = parseInt(elem_id.replace(/.*-(\d{1,4})-.*/m, '$1')) + 1;
|
||||||
|
row.attr('data-id', elem_num);
|
||||||
|
row.find(":input").each(function() {
|
||||||
|
console.log(this);
|
||||||
|
var id = $(this).attr('id').replace('-' + (elem_num - 1) + '-', '-' + (elem_num) + '-');
|
||||||
|
$(this).attr('name', id).attr('id', id).val('').removeAttr("checked");
|
||||||
|
});
|
||||||
|
oldrow.after(row);
|
||||||
|
}); //End add new entry
|
||||||
|
|
||||||
|
//Remove row
|
||||||
|
$this.find("button[data-toggle=fieldset-remove-row]").click(function() {
|
||||||
|
if($this.find("[data-toggle=fieldset-entry]").length > 1) {
|
||||||
|
var thisRow = $(this).closest("[data-toggle=fieldset-entry]");
|
||||||
|
thisRow.remove();
|
||||||
|
}
|
||||||
|
}); //End remove row
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue