Coder Social home page Coder Social logo

benilovj / govuk-form-builder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from x-govuk/govuk-form-builder

0.0 0.0 0.0 3 MB

A form builder for Ruby on Rails that’s compatible with the GOV.UK Design System.

Home Page: https://govuk-form-builder.netlify.app

License: MIT License

Ruby 86.00% Makefile 0.25% SCSS 1.16% Slim 12.59%

govuk-form-builder's Introduction

GOV.UK Form Builder for Ruby on Rails

Tests Maintainability Gem version Gem Test Coverage GitHub license GOV.UK Design System version Rails Ruby

This library provides an easy-to-use form builder for the GOV.UK Design System.

It is intended to make creating forms quick, easy and familiar for Ruby on Rails developers.

Documentation

The gem comes with a full guide that covers most aspects of day-to-day use, along with code and output examples. The examples in the guide are generated from the builder itself so it will always be up to date.

Netlify Status

What’s included

  • 100% compatibility with the GOV.UK Design System
  • Full control of labels, legends, hints, captions and fieldsets
  • No overwriting of Rails’ default form helpers
  • Automatic ARIA associations between hints, errors and inputs
  • Most helpers take blocks for arbitrary content
  • Additional params for programmatically adding hints to check box and radio button collections
  • Full I18n support
  • Automatic handling of ActiveRecord validation error messages
  • No external dependencies
  • An exhaustive test suite
  • Extensive technical documentation

Installation

You can install the form builder gem by running the gem install govuk_design_system_formbuilder or by adding the following line to your Gemfile:

gem 'govuk_design_system_formbuilder'

To make full use of this tool, you will need a Rails application with the latest GOV.UK Frontend assets installed and configured.

To get up and running quickly and easily try kickstarting your project with a pre-configured template:

Setup

To use the form builder in an ad hoc basis you can specify it as an argument to form_for or form_with. These examples are written in Slim but other templating languages like ERB and Haml work just as well.

= form_for @some_object, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f|
  ...

To set it globally, just add this line to your ApplicationController:

class ApplicationController < ActionController::Base
  default_form_builder GOVUKDesignSystemFormBuilder::FormBuilder
end

Now we can get started!

= form_for @person do |f|

  = f.govuk_text_field :full_name, label: { text: "Your full name" }

  = f.govuk_number_field :age, label: { text: "Age" }

  = f.govuk_collection_select :department_id,
    @departments,
    :id,
    :name,
    :description,
    label: { text: "Which department do you work for?" },
    hint: { text: "If you don’t know ask your manager" }

  = f.govuk_submit 'Away we go!'

Developing and running the tests

The form builder is tested with RSpec. To run all the tests first ensure that the development and testing prerequisite gems are installed. At the root of a freshly-cloned repo run:

bundle

Now, if everything was successful, run RSpec:

bundle exec rspec

Contributing

Bug reports and feature requests are most welcome, please raise an issue or submit a pull request.

Currently we’re using GOVUK Lint to ensure code meets the GOV.UK guidelines. Please ensure that any PRs also adhere to this standard.

To help keep the logs clean and tidy, please configure git to use your full name:

git config --global user.name "Julius Hibbert"

Services using this library

Approximately 100 services use this library, here are a few from the DfE, MoJ, and BEIS.

Form building services using this library

Thanks

This project was inspired by Ministry of Justice’s GovukElementsFormBuilder, but is leaner, more modular and written in a more idiomatic style.

govuk-form-builder's People

Contributors

peteryates avatar dependabot[bot] avatar paulrobertlloyd avatar dependabot-preview[bot] avatar jsugarman avatar cpjmcquillan avatar zheileman avatar frankieroberto avatar willfish avatar thomasleese avatar robertm905 avatar david-mears-2 avatar sobakasu avatar callumacrae avatar chrisns avatar darokel avatar duncanjbrown avatar jrmhaig avatar c0nspiracy avatar stevehook avatar tvararu 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.