diff --git a/.gitignore b/.gitignore index 03c1b53ecb..b5009d0cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,130 @@ -npm-debug.log -node_modules +# Created by https://www.gitignore.io/api/osx,node,linux,windows +# Edit at https://www.gitignore.io/?templates=osx,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Dependency directories +node_modules/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +### OSX ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,node,linux,windows + +# Package specific files + build +_build +site dist lib yarn.lock + +# IDE +.vscode + +# Code coverage +coverage +.nyc_output diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000..498baa3fb0 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,15 @@ +# Community Participation Guidelines + +This repository is governed by Mozilla's code of conduct and etiquette guidelines. +For more details, please read the +[Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/). + +## How to Report +For more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page. + + diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 91aa129f11..757feefc6b 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,7 +1,8 @@ ### Prerequisites -- [ ] I have read the [documentation](https://github.com/mozilla-services/react-jsonschema-form/blob/master/README.md#readme); +- [ ] I have read the [documentation](https://react-jsonschema-form.readthedocs.io/); - [ ] In the case of a bug report, I understand that providing a [SSCCE](http://sscce.org/) example is tremendously useful to the maintainers. +- [ ] Ideally, I'm providing a [sample JSFiddle](https://jsfiddle.net/n1k0/f2y3fq7L/6/) or a [shared playground link](https://mozilla-services.github.io/react-jsonschema-form/) demonstrating the issue. ### Description @@ -13,8 +14,6 @@ 2. [Second Step] 3. [and so on...] -Ideally, I'm providing a [sample JSFiddle](https://jsfiddle.net/n1k0/f2y3fq7L/6/) or a [shared playground link](https://mozilla-services.github.io/react-jsonschema-form/) demonstrating the issue. - #### Expected behavior [What you expected to happen] diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md index ff7da6a167..212fe4cd99 100644 --- a/PULL_REQUEST_TEMPLATE.md +++ b/PULL_REQUEST_TEMPLATE.md @@ -7,11 +7,10 @@ If this is related to existing tickets, include links to them as well. ### Checklist * [ ] **I'm updating documentation** - - [ ] I've checked the rendering of the Markdown text I've added - - [ ] If I'm adding a new section, I've updated the Table of Content + - [ ] I've [checked the rendering](https://react-jsonschema-form.readthedocs.io/en/latest/#contributing) of the Markdown text I've added * [ ] **I'm adding or updating code** - [ ] I've added and/or updated tests - - [ ] I've updated docs if needed + - [ ] I've updated [docs](https://react-jsonschema-form.readthedocs.io/) if needed - [ ] I've run `npm run cs-format` on my branch to conform my code to [prettier](https://github.com/prettier/prettier) coding style * [ ] **I'm adding a new feature** - [ ] I've updated the playground with an example use of the feature diff --git a/README.md b/README.md index ca4428cf0b..1e7c658aa0 100644 --- a/README.md +++ b/README.md @@ -1,1889 +1,24 @@ react-jsonschema-form ===================== -[![Build Status](https://travis-ci.org/mozilla-services/react-jsonschema-form.svg)](https://travis-ci.org/mozilla-services/react-jsonschema-form) +[![Build Status](https://travis-ci.org/mozilla-services/react-jsonschema-form.svg?branch=master)](https://travis-ci.org/mozilla-services/react-jsonschema-form) A simple [React](http://facebook.github.io/react/) component capable of building HTML forms out of a [JSON schema](http://json-schema.org/) and using [Bootstrap](http://getbootstrap.com/) semantics by default. -A [live playground](https://mozilla-services.github.io/react-jsonschema-form/) is hosted on gh-pages. - ![](http://i.imgur.com/M8ZCES5.gif) -## Table of Contents - - - [Philosophy](#philosophy) - - [Installation](#installation) - - [As a npm-based project dependency](#as-a-npm-based-project-dependency) - - [As a script served from a CDN](#as-a-script-served-from-a-cdn) - - [Usage](#usage) - - [Form initialization](#form-initialization) - - [Form event handlers](#form-event-handlers) - - [Form submission](#form-submission) - - [Form error event handler](#form-error-event-handler) - - [Form data changes](#form-data-changes) - - [Form field blur events](#form-field-blur-events) - - [Form field focus events](#form-field-focus-events) - - [Submit form programmatically](#submit-form-programmatically) - - [Form customization](#form-customization) - - [The uiSchema object](#the-uischema-object) - - [Alternative widgets](#alternative-widgets) - - [For boolean fields](#for-boolean-fields) - - [For string fields](#for-string-fields) - - [String formats](#string-formats) - - [For number and integer fields](#for-number-and-integer-fields) - - [Disabled fields](#disabled-fields) - - [Read-only fields](#read-only-fields) - - [Hidden widgets](#hidden-widgets) - - [File widgets](#file-widgets) - - [Multiple files](#multiple-files) - - [File widget input ref](#file-widget-input-ref) - - [Object fields ordering](#object-fields-ordering) - - [Object item options](#object-item-options) - - [expandable option](#expandable-option) - - [Array item options](#array-item-options) - - [orderable option](#orderable-option) - - [addable option](#addable-option) - - [removable option](#removable-option) - - [Custom CSS class names](#custom-css-class-names) - - [Custom labels for enum fields](#custom-labels-for-enum-fields) - - [Alternative JSON-Schema compliant approach](#alternative-json-schema-compliant-approach) - - [Disabled attribute for enum fields](#disabled-attribute-for-enum-fields) - - [Multiple choices list](#multiple-choices-list) - - [Autogenerated widget ids](#autogenerated-widget-ids) - - [Form action buttons](#form-action-buttons) - - [Help texts](#help-texts) - - [Title texts](#title-texts) - - [Description texts](#description-texts) - - [Auto focus](#auto-focus) - - [Textarea rows option](#textarea-rows-option) - - [Placeholders](#placeholders) - - [Field labels](#field-labels) - - [HTML5 Input Types](#html5-input-types) - - [Form attributes](#form-attributes) - - [Form disable](#form-disable) - - [Advanced customization](#advanced-customization) - - [Field template](#field-template) - - [Array Field Template](#array-field-template) - - [Object Field Template](#object-field-template) - - [Error List template](#error-list-template) - - [Id prefix](#id-prefix) - - [Custom widgets and fields](#custom-widgets-and-fields) - - [Custom widget components](#custom-widget-components) - - [Custom component registration](#custom-component-registration) - - [Custom widget options](#custom-widget-options) - - [Customizing widgets text input](#customizing-widgets-text-input) - - [Custom field components](#custom-field-components) - - [Field props](#field-props) - - [The registry object](#the-registry-object) - - [The formContext object](#the-formcontext-object) - - [Custom array field buttons](#custom-array-field-buttons) - - [Custom SchemaField](#custom-schemafield) - - [Customizing the default fields and widgets](#customizing-the-default-fields-and-widgets) - - [Custom titles](#custom-titles) - - [Custom descriptions](#custom-descriptions) - - [Form data validation](#form-data-validation) - - [Live validation](#live-validation) - - [HTML5 Validation](#html5-validation) - - [Custom validation](#custom-validation) - - [Custom error messages](#custom-error-messages) - - [Error List Display](#error-list-display) - - [The case of empty strings](#the-case-of-empty-strings) - - [Styling your forms](#styling-your-forms) - - [Schema definitions and references](#schema-definitions-and-references) - - [Property dependencies](#property-dependencies) - - [Unidirectional](#unidirectional) - - [Bidirectional](#bidirectional) - - [Schema dependencies](#schema-dependencies) - - [Conditional](#conditional) - - [Dynamic](#dynamic) - - [JSON Schema supporting status](#json-schema-supporting-status) - - [Tips and tricks](#tips-and-tricks) - - [Contributing](#contributing) - - [Coding style](#coding-style) - - [Development server](#development-server) - - [Tests](#tests) - - [TDD](#tdd) - - [Releasing](#releasing) - - [FAQ](#faq) - - [Q: Does rjsf support oneOf, anyOf, multiple types in an array, etc.?](#q-does-rjsf-support-oneof-anyof-multiple-types-in-an-array-etc) - - [Q: Will react-jsonschema-form support Material, Ant-Design, Foundation, or [some other specific widget library or frontend style]?](#q-will-react-jsonschema-form-support-material-ant-design-foundation-or-some-other-specific-widget-library-or-frontend-style) - - [License](#license) - ---- - -## Philosophy - -react-jsonschema-form is meant to automatically generate a React form based on a [JSON Schema](http://json-schema.org/). It is a major component in the [kinto-admin](https://github.com/Kinto/kinto-admin/) project. If you want to generate a form for any data, sight unseen, simply given a JSON schema, react-jsonschema-form may be for you. If you have _a priori_ knowledge of your data and want a toolkit for generating forms for it, you might look elsewhere. - -react-jsonschema-form validates that the data conforms to the given schema, but doesn't prevent the user from inputing data that doesn't fit (for example, stripping non-numbers from a number field, or adding values to an array that is already "full"). - -## Installation - -Requires React 15.0.0+. - -> Note: The `master` branch of the repository reflects ongoing development. Releases are published as [tags](https://github.com/mozilla-services/react-jsonschema-form/releases). You should never blindly install from `master`, but rather check what the available stable releases are. - - -### As a npm-based project dependency - -``` -$ npm install react-jsonschema-form --save -``` - -> Note: While the library renders [Bootstrap](http://getbootstrap.com/) HTML semantics, you have to build and load the Bootstrap styles on your own. - -### As a script served from a CDN - -```html - -``` - -Source maps are available at [this url](https://unpkg.com/react-jsonschema-form/dist/react-jsonschema-form.js.map). - -> Note: The CDN version **does not** embed `react` or `react-dom`. - -You'll also need to alias the default export property to use the Form component: - -```jsx -const Form = JSONSchemaForm.default; -// or -const {default: Form} = JSONSchemaForm; -``` - -## Usage - -```jsx -import React, { Component } from "react"; -import { render } from "react-dom"; - -import Form from "react-jsonschema-form"; - -const schema = { - title: "Todo", - type: "object", - required: ["title"], - properties: { - title: {type: "string", title: "Title", default: "A new task"}, - done: {type: "boolean", title: "Done?", default: false} - } -}; - -const log = (type) => console.log.bind(console, type); - -render(( -
-), document.getElementById("app")); -``` - -This will generate a form like this (assuming you loaded the standard [Bootstrap](http://getbootstrap.com/) stylesheet): - -![](http://i.imgur.com/DZQYPyu.png) - -### Form initialization - -Often you'll want to prefill a form with existing data; this is done by passing a `formData` prop object matching the schema: - -```jsx -const formData = { - title: "First task", - done: true -}; - -render(( - -), document.getElementById("app")); -``` - -> Note: If your form has a single field, pass a single value to `formData`. ex: `formData='Charlie'` - -> WARNING: If you have situations where your parent component can re-render, make sure you listen to the `onChange` event and update the data you pass to the `formData` attribute. - -### Form event handlers - -#### Form submission - -You can pass a function as the `onSubmit` prop of your `Form` component to listen to when the form is submitted and its data are valid. It will be passed a result object having a `formData` attribute, which is the valid form data you're usually after: - -```js -const onSubmit = ({formData}) => console.log("Data submitted: ", formData); - -render(( - -), document.getElementById("app")); -``` - -#### Form error event handler - -To react when submitted form data are invalid, pass an `onError` handler. It will be passed the list of encountered errors: - -```js -const onError = (errors) => console.log("I have", errors.length, "errors to fix"); - -render(( - -), document.getElementById("app")); -``` - -#### Form data changes - -If you plan on being notified every time the form data are updated, you can pass an `onChange` handler, which will receive the same args as `onSubmit` any time a value is updated in the form. - -#### Form field blur events - -Sometimes you may want to trigger events or modify external state when a field has been touched, so you can pass an `onBlur` handler, which will receive the id of the input that was blurred and the field value. - -#### Form field focus events - -Sometimes you may want to trigger events or modify external state when a field has been focused, so you can pass an `onFocus` handler, which will receive the id of the input that is focused and the field value. - -### Submit form programmatically -You can use the reference to get your `Form` component and call the `submit` method to submit the form programmatically without a submit button. -This method will dispatch the `submit` event of the form, and the function, that is passed to `onSubmit` props, will be called. - -```js -const onSubmit = ({formData}) => console.log("Data submitted: ", formData); -let yourForm; - -render(( - -), document.getElementById("app")); -``` - -### Alternative widgets - -The uiSchema `ui:widget` property tells the form which UI widget should be used to render a field. - -Example: - -```jsx -const uiSchema = { - done: { - "ui:widget": "radio" // could also be "select" - } -}; - -render(( - -), document.getElementById("app")); -``` - -Here's a list of supported alternative widgets for different JSONSchema data types: - -#### For `boolean` fields - - * `radio`: a radio button group with `true` and `false` as selectable values; - * `select`: a select box with `true` and `false` as options; - * by default, a checkbox is used - -> Note: To set the labels for a boolean field, instead of using `true` and `false` you can set `enumNames` in your schema. Note that `enumNames` belongs in your `schema`, not the `uiSchema`, and the order is always `[true, false]`. - -#### For `string` fields - - * `textarea`: a `textarea` element is used; - * `password`: an `input[type=password]` element is used; - * `color`: an `input[type=color]` element is used; - * by default, a regular `input[type=text]` element is used. - -##### String formats - -The built-in string field also supports the JSONSchema `format` property, and will render an appropriate widget by default for the following string formats: - -- `email`: An `input[type=email]` element is used; -- `uri`: An `input[type=url]` element is used; -- `data-url`: By default, an `input[type=file]` element is used; in case the string is part of an array, multiple files will be handled automatically (see [File widgets](#file-widgets)). -- `date`: By default, an `input[type=date]` element is used; -- `date-time`: By default, an `input[type=datetime-local]` element is used. - -![](http://i.imgur.com/xqu6Lcp.png) - -Please note that, even though they are standardized, `datetime-local` and `date` input elements are not yet supported by Firefox and IE. If you plan on targeting these platforms, two alternative widgets are available: - -- `alt-datetime`: Six `select` elements are used to select the year, the month, the day, the hour, the minute and the second; -- `alt-date`: Three `select` elements are used to select the year, month and the day. - -![](http://i.imgur.com/VF5tY60.png) - -You can customize the list of years displayed in the `year` dropdown by providing a ``yearsRange`` property to ``ui:options`` in your uiSchema. Its also possible to remove the `Now` and `Clear` buttons with the `hideNowButton` and `hideClearButton` options. - -```jsx -uiSchema: { - a_date: { - "alt-datetime": { - "ui:widget": "alt-datetime", - "ui:options": { - yearsRange: [1980, 2030], - hideNowButton: true, - hideClearButton: true, - }, - }, - }, -}, -``` - -#### For `number` and `integer` fields - - * `updown`: an `input[type=number]` updown selector; - * `range`: an `input[type=range]` slider; - * `radio`: a radio button group with enum values. This can only be used when `enum` values are specified for this input. - * By default, a regular `input[type=text]` element is used. - -> Note: If JSONSchema's `minimum`, `maximum` and `multipleOf` values are defined, the `min`, `max` and `step` input attributes values will take those values. - -#### Disabled fields - -The `ui:disabled` uiSchema directive will disable all child widgets from a given field. - -#### Read-only fields - -The `ui:readonly` uiSchema directive will mark all child widgets from a given field as read-only. - -> Note: If you're wondering about the difference between a `disabled` field and a `readonly` one: Marking a field as read-only will render it greyed out, but its text value will be selectable. Disabling it will prevent its value to be selected at all. - -#### Hidden widgets - -It's possible to use a hidden widget for a field by setting its `ui:widget` uiSchema directive to `hidden`: - -```js -const schema = { - type: "object", - properties: { - foo: {type: "boolean"} - } -}; - -const uiSchema = { - foo: {"ui:widget": "hidden"} -}; -``` - -Notes: - - - Hiding widgets is only supported for `boolean`, `string`, `number` and `integer` schema types; - - A hidden widget takes its value from the `formData` prop. - -#### File widgets - -This library supports a limited form of `input[type=file]` widgets, in the sense that it will propagate file contents to form data state as [data-url](http://dataurl.net/#about)s. - -There are two ways to use file widgets. - -1. By declaring a `string` json schema type along a `data-url` [format](#string-formats): -```js -const schema = { - type: "string", - format: "data-url", -}; -``` - -2. By specifying a `ui:widget` field uiSchema directive as `file`: -```js -const schema = { - type: "string", -}; - -const uiSchema = { - "ui:widget": "file", -}; -``` - -##### Multiple files - -Multiple files selectors are supported by defining an array of strings having `data-url` as a format: - -```js -const schema = { - type: "array", - items: { - type: "string", - format: "data-url", - } -}; -``` - -> Note that storing large dataURIs into form state might slow rendering. - -##### File widget input ref - -The included `FileWidget` exposes a reference to the `` element node as an `inputRef` component property. - -This allows you to programmatically trigger the browser's file selector, which can be used in a custom file widget. - -### Object fields ordering - -Since the order of object properties in Javascript and JSON is not guaranteed, the `uiSchema` object spec allows you to define the order in which properties are rendered using the `ui:order` property: - -```jsx -const schema = { - type: "object", - properties: { - foo: {type: "string"}, - bar: {type: "string"} - } -}; - -const uiSchema = { - "ui:order": ["bar", "foo"] -}; - -render(( - -), document.getElementById("app")); -``` - -If a guaranteed fixed order is only important for some fields, you can insert a wildcard `"*"` item in your `ui:order` definition. All fields that are not referenced explicitly anywhere in the list will be rendered at that point: - -```js -const uiSchema = { - "ui:order": ["bar", "*"] -}; -``` - -### Object item options - -#### `expandable` option - -If `additionalProperties` contains a schema object, an add button for new properies is shown by default. The UX for editing properties whose names are user-defined is still experimental. - -You can turn support for `additionalProperties` off with the `expandable` option in `uiSchema`: - -```jsx -const uiSchema = { - "ui:options": { - expandable: false - } -}; -``` - -### Array item options - -#### `orderable` option - -Array items are orderable by default, and react-jsonschema-form renders move up/down buttons alongside them. The `uiSchema` object spec allows you to disable ordering: - -```jsx -const schema = { - type: "array", - items: { - type: "string" - } -}; - -const uiSchema = { - "ui:options": { - orderable: false - } -}; -``` - -#### `addable` option - -If either `items` or `additionalItems` contains a schema object, an add button for new items is shown by default. You can turn this off with the `addable` option in `uiSchema`: - -```jsx -const uiSchema = { - "ui:options": { - addable: false - } -}; -``` - -#### `removable` option - -A remove button is shown by default for an item if `items` contains a schema object, or the item is an `additionalItems` instance. You can turn this off with the `removable` option in `uiSchema`: - -```jsx -const uiSchema = { - "ui:options": { - removable: false - } -}; -``` - -### Custom CSS class names - -The uiSchema object accepts a `classNames` property for each field of the schema: - -```jsx -const uiSchema = { - title: { - classNames: "task-title foo-bar" - } -}; -``` - -Will result in: - -```html - -``` - -### Custom labels for `enum` fields - -This library supports the [`enumNames`](https://github.com/json-schema/json-schema/wiki/enumNames-%28v5-proposal%29) property for `enum` fields, which allows defining custom labels for each option of an `enum`: - -```js -const schema = { - type: "number", - enum: [1, 2, 3], - enumNames: ["one", "two", "three"] -}; -``` - -This will be rendered using a select box like this: - -```html - -``` - -Note that string representations of numbers will be cast back and reflected as actual numbers into form state. - -#### Alternative JSON-Schema compliant approach - -JSON Schema has an alternative approach to enumerations; react-jsonschema-form supports it as well. - -```js -const schema = { - "type": "number", - "anyOf": [ - { - "type": "number", - "title": "one", - "enum": [ - 1 - ] - }, - { - "type": "number", - "title": "two", - "enum": [ - 2 - ] - }, - { - "type": "number", - "title": "three", - "enum": [ - 3 - ] - } - ] -}; -``` - -This will be rendered as follows: - -```html - -``` - -A live example of both approaches side-by-side can be found in the **Alternatives** tab of the [playground](https://mozilla-services.github.io/react-jsonschema-form/). - -### Disabled attribute for `enum` fields - -To disable an option, use the `enumDisabled` property in uiSchema. - -```js -const schema = { - type: "string", - enum: ["one", "two", "three"], -}; - -const uiSchema={ - "ui:enumDisabled": ['two'], -} -``` - -This will be rendered using a select box as follows: - -```html - -``` - -### Multiple-choice list - -The default behavior for array fields is a list of text inputs with add/remove buttons. There are two alternative widgets for picking multiple elements from a list of choices. Typically this applies when a schema has an `enum` list for the `items` property of an `array` field, and the `uniqueItems` property set to `true`. - -Example: - -```js -const schema = { - type: "array", - title: "A multiple-choice list", - items: { - type: "string", - enum: ["foo", "bar", "fuzz", "qux"], - }, - uniqueItems: true -}; -``` - -By default, this will render a multiple select box. If you prefer a list of checkboxes, just set the uiSchema `ui:widget` directive to `checkboxes` for that field: - -```js -const uiSchema = { - "ui:widget": "checkboxes" -}; -``` - -Note that when an array property is marked as `required`, an empty array is considered valid. If array needs to be populated, you can specify the minimum number of items using the `minItems` property. - -Example: - -```js -const schema = { - type: "array", - minItems: 2, - title: "A multiple-choice list", - items: { - type: "string", - enum: ["foo", "bar", "fuzz", "qux"], - }, - uniqueItems: true -}; -``` - -By default, checkboxes are stacked. If you prefer them inline, set the `inline` property to `true`: - -```js -const uiSchema = { - "ui:widget": "checkboxes", - "ui:options": { - inline: true - } -}; -``` - -See the "Arrays" section of the [playground](https://mozilla-services.github.io/react-jsonschema-form/) for cool demos. - -### Autogenerated widget ids - -By default, this library will generate ids unique to the form for all rendered widgets. If you plan on using multiple instances of the `Form` component in a same page, it's wise to declare a root prefix for these, using the `ui:rootFieldId` uiSchema directive: - -```js -const uiSchema = { - "ui:rootFieldId": "myform" -}; -``` - -So all widgets will have an id prefixed with `myform`. - -### Form action buttons - -You can provide custom buttons to your form via the `Form` component's `children`. Otherwise a default submit button will be rendered. - -```jsx -render(( - -), document.getElementById("app")); -``` - -> **Warning:** There needs to be a button or an input with `type="submit"` to trigger the form submission (and then the form validation). - -### Help text - -Sometimes it's convenient to add text next to a field to guide the end user filling it. This is the purpose of the `ui:help` uiSchema directive: - -```js -const schema = {type: "string"}; -const uiSchema = { - "ui:widget": "password", - "ui:help": "Hint: Make it strong!" -}; -``` - -![](http://i.imgur.com/scJUuZo.png) - -Help texts work for any kind of field at any level, and will always be rendered immediately below the field component widget(s) (after contextualized errors, if any). - -### Title texts - -Sometimes it's convenient to change a field's title. this is the purpose of the `ui:title` uiSchema directive: - -```js -const schema = {type: "string"}; -const uiSchema = { - "ui:widget": "password", - "ui:title": "Your password" -}; -``` - -### Description texts - -Sometimes it's convenient to change description a field. This is the purpose of the `ui:description` uiSchema directive: - -```js -const schema = {type: "string"}; -const uiSchema = { - "ui:widget": "password", - "ui:description": "The best password" -}; -``` - -### Auto focus - -If you want to automatically focus on a text input or textarea input, set the `ui:autofocus` uiSchema directive to `true`. - -```js -const schema = {type: "string"}; -const uiSchema = { - "ui:widget": "textarea", - "ui:autofocus": true -} -``` - -### Textarea `rows` option - -You can set the initial height of a textarea widget by specifying `rows` option. - -```js -const schema = {type: "string"}; -const uiSchema = { - "ui:widget": "textarea", - "ui:options": { - rows: 15 - } -} -``` - -### Placeholders - -You can add placeholder text to an input by using the `ui:placeholder` uiSchema directive: - -```jsx -const schema = {type: "string", format: "uri"}; -const uiSchema = { - "ui:placeholder": "http://" -}; -``` - -![](http://i.imgur.com/MbHypKg.png) - -Fields using `enum` can also use `ui:placeholder`. The value will be used as the text for the empty option in the select widget. - -```jsx -const schema = {type: "string", enum: ["First", "Second"]}; -const uiSchema = { - "ui:placeholder": "Choose an option" -}; -``` - -### Field labels - -Field labels are rendered by default. Labels may be omitted by setting the `label` option to `false` in the `ui:options` uiSchema directive. - -```jsx -const schema = {type: "string"}; -const uiSchema = { - "ui:options": { - label: false - } -}; -``` - -### HTML5 Input Types - -To change the input type (for example, `tel` or `email`) you can specify the `inputType` in the `ui:options` uiSchema directive. - -```jsx -const schema = {type: "string"}; -const uiSchema = { - "ui:options": { - inputType: 'tel' - } -}; -``` - -### Form attributes - -The `Form` component supports the following html attributes: - -```jsx - -``` - -### Form disable - -Its possible to disable the whole form by setting the `disabled` prop. The `disabled` prop is then forwarded down thru each field of the form. - -```jsx - -``` - -If you just want to disable some of the fields see the `ui:disabled` parameter in the uiSchema directive. - -## Advanced customization - - -_ | Custom Field | Custom Template | Custom Widget ---|---------- | ------------- | ---- -What it does | Overrides all behaviour | Overrides just the layout | Overrides just the input box (not layout, labels, or help, or validation) -Usage | Global or per-field | Only global | Global or per-field -Global Example | `` | `` | `` -Per-Field Example | `"ui:field": MyField` | N/A | `"ui:widget":MyWidget` -Documentation | [Field](#field-props) | [Field Template](#field-template) - [Array Template](#array-field-template) - [Object Template](#object-field-template) - [Error List Template](#error-list-template) | [Custom Widgets](#custom-widget-components) - -### Field template - -To take control over the inner organization of each field (each form row), you can define a *field template* for your form. - -A field template is basically a React stateless component being passed field-related props, allowing you to structure your form row as you like. - -```jsx -function CustomFieldTemplate(props) { - const {id, classNames, label, help, required, description, errors, children} = props; - return ( -Yeah, I'm pretty dumb.
-Yeah, I'm pretty dumb.
+