Skip to content

Commit 271c8ef

Browse files
committed
Expose name prop on input components for use in forms
1 parent a48103e commit 271c8ef

File tree

8 files changed

+67
-23
lines changed

8 files changed

+67
-23
lines changed

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"fast-isnumeric": "^1.1.3",
6565
"is-absolute-url": "^2.1.0",
6666
"prop-types": "^15.7.2",
67-
"ramda": "^0.25.0",
67+
"ramda": "^0.27.0",
6868
"react": "^16.13.1",
6969
"react-dom": "^16.13.0",
7070
"reactstrap": "^8.5.1"

src/components/form/Form.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ Form.propTypes = {
7575
*/
7676
key: PropTypes.string,
7777

78+
/**
79+
* The URI of a program that processes the information submitted via the form.
80+
*/
81+
action: PropTypes.string,
82+
83+
/**
84+
* Defines which HTTP method to use when submitting the form. Can be GET
85+
* (default) or POST.
86+
*/
87+
method: PropTypes.oneOf(["GET", "POST"]),
88+
7889
/**
7990
* Use inline=True to apply the `form-inline` class, allowing you to display
8091
* a series of labels, form controls, and buttons on a single horizontal row.

src/components/input/Checkbox.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ Checkbox.propTypes = {
131131
/**
132132
* Disabled the Checkbox
133133
*/
134-
disabled: PropTypes.bool
134+
disabled: PropTypes.bool,
135+
136+
/**
137+
* The name of the control, which is submitted with the form data.
138+
*/
139+
name: PropTypes.string
135140
};
136141

137142
export default Checkbox;

src/components/input/Checklist.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import {append, contains, without} from 'ramda';
3+
import {append, includes, without} from 'ramda';
44
import classNames from 'classnames';
55
import CustomInput from '../../private/CustomInput';
66

@@ -18,7 +18,7 @@ import CustomInput from '../../private/CustomInput';
1818
* https://getbootstrap.com/docs/4.4/components/forms/#checkboxes-and-radios-1
1919
*/
2020
const Checklist = props => {
21-
const {className, id, options, style, key, loading_state} = props;
21+
const {className, id, options, style, key, loading_state, name} = props;
2222

2323
const listItem = option => {
2424
const {
@@ -36,7 +36,7 @@ const Checklist = props => {
3636
switch: switches
3737
} = props;
3838

39-
const checked = contains(option.value, value);
39+
const checked = includes(option.value, value);
4040

4141
const mergedLabelStyle = checked
4242
? {...labelStyle, ...labelCheckedStyle}
@@ -48,6 +48,8 @@ const Checklist = props => {
4848
return (
4949
<CustomInput
5050
id={inputId}
51+
name={name}
52+
value={option.value}
5153
labelId={option.label_id}
5254
checked={checked}
5355
className={inputClassName}
@@ -62,7 +64,7 @@ const Checklist = props => {
6264
inline={inline}
6365
onChange={() => {
6466
let newValue;
65-
if (contains(option.value, value)) {
67+
if (includes(option.value, value)) {
6668
newValue = without([option.value], value);
6769
} else {
6870
newValue = append(option.value, value);
@@ -84,14 +86,16 @@ const Checklist = props => {
8486
>
8587
<input
8688
id={inputId}
89+
name={name}
90+
value={option.value}
8791
checked={checked}
8892
className={classNames('form-check-input', inputClassName)}
8993
disabled={Boolean(option.disabled)}
9094
style={inputStyle}
9195
type="checkbox"
9296
onChange={() => {
9397
let newValue;
94-
if (contains(option.value, value)) {
98+
if (includes(option.value, value)) {
9599
newValue = without([option.value], value);
96100
} else {
97101
newValue = append(option.value, value);
@@ -300,7 +304,12 @@ Checklist.propTypes = {
300304
* local: window.localStorage, data is kept after the browser quit.
301305
* session: window.sessionStorage, data is cleared once the browser quit.
302306
*/
303-
persistence_type: PropTypes.oneOf(['local', 'session', 'memory'])
307+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
308+
309+
/**
310+
* The name of the control, which is submitted with the form data.
311+
*/
312+
name: PropTypes.string
304313
};
305314

306315
Checklist.defaultProps = {

src/components/input/RadioButton.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ RadioButton.propTypes = {
132132
/**
133133
* Disable the RadioButton.
134134
*/
135-
disabled: PropTypes.bool
135+
disabled: PropTypes.bool,
136+
137+
/**
138+
* The name of the control, which is submitted with the form data.
139+
*/
140+
name: PropTypes.string
136141
};
137142

138143
export default RadioButton;

src/components/input/RadioItems.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import CustomInput from '../../private/CustomInput';
1111
* siblings of each other.
1212
*/
1313
const RadioItems = props => {
14-
const {id, className, style, options, key, loading_state} = props;
14+
const {id, className, style, options, key, loading_state, name} = props;
1515

1616
const listItem = option => {
1717
const {
@@ -41,6 +41,8 @@ const RadioItems = props => {
4141
return (
4242
<CustomInput
4343
id={inputId}
44+
name={name}
45+
value={option.value}
4446
labelId={option.label_id}
4547
checked={checked}
4648
className={inputClassName}
@@ -71,6 +73,8 @@ const RadioItems = props => {
7173
>
7274
<input
7375
id={inputId}
76+
name={name}
77+
value={option.value}
7478
checked={checked}
7579
className={classNames('form-check-input', inputClassName)}
7680
disabled={Boolean(option.disabled)}
@@ -280,7 +284,12 @@ RadioItems.propTypes = {
280284
* local: window.localStorage, data is kept after the browser quit.
281285
* session: window.sessionStorage, data is cleared once the browser quit.
282286
*/
283-
persistence_type: PropTypes.oneOf(['local', 'session', 'memory'])
287+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
288+
289+
/**
290+
* The name of the control, which is submitted with the form data.
291+
*/
292+
name: PropTypes.string
284293
};
285294

286295
RadioItems.defaultProps = {

src/components/input/Select.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ Select.propTypes = {
184184
* local: window.localStorage, data is kept after the browser quit.
185185
* session: window.sessionStorage, data is cleared once the browser quit.
186186
*/
187-
persistence_type: PropTypes.oneOf(['local', 'session', 'memory'])
187+
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
188+
189+
/**
190+
* The name of the control, which is submitted with the form data.
191+
*/
192+
name: PropTypes.string
188193
};
189194

190195
export default Select;

0 commit comments

Comments
 (0)