1.1.6 • Published 5 years ago

wtforms-helper v1.1.6

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

WTForms Helper

Why does this exist?

Often, in our applications, we have some kind of data that gets pulled from a database, passed to the client, edited, and then posted back to the server and subsequently written to the database. I've recently been using Python Flask with Flask-SQLAlchemy and Flask-WTForms to handle the infrastructure that supports this kind of thing and over last few applications I've sort of generalized the methods that I was using to show form changes that a user has made when doing this sort of thing. This project is the (still-in-development) outcome of that.

Installation

npm install wtforms-helper

Usage

This is designed to be used with browserify.

Example

... on the to-do list ...

Options

Form Field Type

form_item_id: must match the wtforms field ID exactly (with a prefixed #) form_item_label: must match the wtforms field displayed label - we keep this in case of page reloads if the label was modified (maybe not necessary but easy enough to put in) form_item_type:

  • datetimefield: covers DateField and DateTimeField
  • stringfield: covers TextField and TextAreaField
  • floatfield: covers FloatField
  • integerfield: covers IntegerField
  • checkbox: covers RadioField
  • selectfield: covers SelectField

show_original_value:

  • true: shows the value that is stored in the database for that field
  • false: shows 'Modified'

value_is_original: should always be true when you set this up. Gets toggled between true/false by the method. Don't change this from true - just there for recordkeeping if you're using this to toggle on/off (enabled/disabled) a submit button for the form.

original_value: this should pull from somewhere in the html, what the stored value for that field is. You will have to get creative for where to put some of these such as multiformfield things etc..

Note about implementation

This takes a little server-side setup to get this to work (you have to add a data attribute to each of the form labels, containing the stored value of the corresponding field). Doesn't seem ideal but....

I first tried serializing the values on initial page load and then comparing that value to the current serialized value on any sort of change but any time the form submit failed validation it would cause any entries which had been changed to show up as 'unchanged' according to the method. This is obviously not what we want.

The other option I thought of would have been to have the JS make an API call back to the application each time the page loaded but this seems to introduce both more overhead and more potential issues.

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago