-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2766 move new field rendering to a field group component and write t…
…ests for that
- Loading branch information
Josh Pollock
committed
Oct 19, 2018
1 parent
26b7a9c
commit 51184d1
Showing
10 changed files
with
360 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import {Component, Fragment} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {CalderaFormsFieldPropType} from "./CalderaFormsFieldRender"; | ||
|
||
/** | ||
* Render a Caldera Forms v2 field | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @param props | ||
* @return {*} | ||
* @constructor | ||
*/ | ||
export const CalderaFormsFieldGroup = (props) => { | ||
const {field, onChange, shouldDisable, shouldShow} = props; | ||
const { | ||
type, | ||
outterIdAttr, | ||
fieldId, | ||
fieldLabel, | ||
fieldCaption, | ||
required, | ||
fieldPlaceHolder, | ||
fieldDefault, | ||
fieldValue, | ||
fieldIdAttr, | ||
} = field; | ||
|
||
if (!shouldShow) { | ||
return <Fragment/>; | ||
} | ||
return ( | ||
|
||
<div className={'form-group cf2-field-group'}> | ||
<label | ||
className={'control-label'} | ||
htmlFor={fieldIdAttr} | ||
> | ||
{fieldLabel} | ||
</label> | ||
<input | ||
type={type} | ||
disabled={shouldDisable} | ||
value={fieldValue} | ||
required={required} | ||
className={'form-control'} | ||
id={fieldIdAttr} | ||
placeholder={fieldPlaceHolder} | ||
onChange={onChange} | ||
/> | ||
</div> | ||
|
||
); | ||
|
||
} | ||
|
||
|
||
|
||
/** | ||
* Prop Type definitions for CalderaFormsFieldGroup component | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @type {{field: *, onChange: (e|*), shouldShow: *, shouldDisable: *}} | ||
*/ | ||
CalderaFormsFieldGroup.propTypes = { | ||
field: CalderaFormsFieldPropType, | ||
onChange: PropTypes.func.isRequired, | ||
shouldShow: PropTypes.bool, | ||
shouldDisable: PropTypes.bool | ||
}; | ||
|
||
/** | ||
* Default props for the CalderaFormsFieldGroup component | ||
* | ||
* @since 1.8.0 | ||
* | ||
* @type {{shouldShow: boolean, shouldDisable: boolean, fieldValue: string}} | ||
*/ | ||
CalderaFormsFieldGroup.defaultProps = { | ||
shouldShow: true, | ||
shouldDisable: false, | ||
fieldValue: '' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,7 +236,7 @@ export class CalderaFormsRender extends Component { | |
})} | ||
|
||
</Fragment> | ||
) | ||
); | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {CalderaFormsFieldRender,CalderaFormsFieldPropType} from "./CalderaFormsFieldRender"; | ||
import {CalderaFormsRender} from "./CalderaFormsRender"; | ||
import {CalderaFormsFieldGroup} from "./CalderaFormsFieldGroup"; | ||
|
||
export{ | ||
CalderaFormsFieldGroup, | ||
CalderaFormsFieldPropType, | ||
CalderaFormsFieldRender, | ||
CalderaFormsRender | ||
} |
Oops, something went wrong.