GithubHelp home page GithubHelp logo

marr / newforms-examples Goto Github PK

View Code? Open in Web Editor NEW

This project forked from insin/newforms-examples

0.0 1.0 0.0 928 KB

Examples repository for newforms / React

HTML 4.42% CSS 1.88% JavaScript 93.70%

newforms-examples's Introduction

newforms-examples

Examples repository for newforms.

A basic form with as many of the default newforms fields and widgets as possible, showing a range of the options supported by the fields.

This example also demonstrates:

  • overriding the default render() method
  • implementing custom rendering using BoundFields and JSX.

This example shows how you could write a custom, reusable layout for laying out form fields in grids based on a specification like this:

GridLayout({
  layout: [
    [ 'name'      ]
  , [ 'theme'     ]
  , [ 'startDate' , 'releaseDate' ]
  , [ 'state'     , 'resources'   ]
  , [ 'project'   ]
  , [ 'estimate'  ]
  , [ 'notes'     ]
  ]
, fillerCssClass: 'empty'
, topErrorCssClass: 'top-errors'
})

This is backed up with a base FormLayout object and a new base LayoutForm which uses it - these could serve as the basis for any kind of reusable custom layout you like with BoundFields and JSX.

It also has examples of:

  • using a form's constructor to implement dynamic choices.
  • full-form cleaning by implementing a clean() method.
  • a standard pattern for using a newforms Forn within a React component, holding the form as state.

An example of implementing a custom layout using Bootstrap and using some React state to dynamically control which fields are displayed.

It also has examples of:

  • extending a RadioFieldRenderer to customise its output.
  • implementing a clean<FieldName>() function for per-field validation logic.

An example of implementing (multiple) forms with "Add Another" functionality simply by incrementing a FormSet's extra property.

This example also shows:

  • using prefix to have multiple instances of the same FormSet on a page without id/name conflicts.
  • validating and getting cleanedData out of multiple FormSets.
  • reusing a component for common contact fields.
  • implementing a Bootstrap 3 form layout using a form.boundFieldsObj() and a custom field rendering function.

Examples elsewhere

Uses the same Form on the client and server for pre-rendering and progressive enhancement.

Also reuses the same Form for API validation.

Uses a FormSet to implement a list of forms which can be added to and deleted from.

Uses BoundField and Form methods to highlight when fields become required or their valid/invalid status changes.

newforms-examples's People

Contributors

insin avatar marr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.