Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HTML5 input types to TextField #19

Merged
merged 3 commits into from
Jun 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ npm-debug.log
packages/*/coverage
packages/*/lib
packages/*/node_modules
.idea
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ const ExplicitAutoForm = () =>
| `RadioField` | Radio checkbox. | `allowedValues` |
| `SelectField` | Select. | `allowedValues` |
| `SubmitField` | Submit button. | *none* |
| `TextField` | Text input. | `type: String` |
| `TextField` | Text input. `type` can be overriden by valid HTML input types | `type: String` |

**Note:** You can pass `component` prop to `AutoField` to bypass field guessing algorithm.

Expand Down Expand Up @@ -261,6 +261,14 @@ const PersonSchema = new SimpleSchema({
| `type` | `func` | Field type. |
| `value` | `any` | Field value. |

Default value of `text` is provided to text inputs but it can be overriden

```js
<TextField type="password" /> // html password field
<TextField type="color" /> // html5 color picker
<TextField type="tel" /> // html5 phone input
```

Every prop can be overriden, but `label`, `placeholder` and `disabled` have special semantics:

```js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Text = props =>
name={props.name}
onChange={event => props.onChange(event.target.value)}
placeholder={props.placeholder}
type="text"
type={props.type || 'text'}
value={props.value}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Text = props =>
name={props.name}
onChange={event => props.onChange(event.target.value)}
placeholder={props.placeholder}
type="text"
type={props.type || 'text'}
value={props.value}
/>
</FormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import classnames from 'classnames';
import {connectField} from 'uniforms';

const Text = ({
type="text",
className,
disabled,
error,
Expand All @@ -13,8 +14,7 @@ const Text = ({
required,
value,
...props
}) =>
<section className={classnames(className, {disabled, error, required}, 'field')} {...props}>
}) => <section className={classnames(className, {disabled, error, required}, 'field')} {...props}>
{label && (
<label>
{label}
Expand All @@ -26,10 +26,9 @@ const Text = ({
name={name}
onChange={event => onChange(event.target.value)}
placeholder={placeholder}
type="text"
type={type}
value={value}
/>
</section>
;
</section>

export default connectField(Text);
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React from 'react';
import {connectField} from 'uniforms';

const Text = ({
type="text",
disabled,
label,
name,
onChange,
placeholder,
value,
...props
}) =>
<section {...props}>
}) => <section {...props}>
{label && (
<label>
{label}
Expand All @@ -22,10 +22,10 @@ const Text = ({
disabled={disabled}
onChange={event => onChange(event.target.value)}
placeholder={placeholder}
type="text"
type={type}
value={value}
/>
</section>
</section>
;

export default connectField(Text);