Skip to content

Commit

Permalink
clean up and inline docs in the CalderaFormsFieldGroup component #2766
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Nov 19, 2018
1 parent 2b48a85 commit 71cc344
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 40 deletions.
24 changes: 24 additions & 0 deletions clients/render/build/index.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -25999,6 +25999,15 @@ var CalderaFormsFieldGroup = function CalderaFormsFieldGroup(props) {
}
};

/**
* Create error markup
*
* @since 1.8.0
*
* @param {*} message Message object -- {message: String, error: Bool }
* @return {*}
* @constructor
*/
function Error(message) {
return wp.element.createElement(
'span',
Expand All @@ -26014,6 +26023,15 @@ var CalderaFormsFieldGroup = function CalderaFormsFieldGroup(props) {
);
};

/**
* Create error or non-error markup
*
* @since 1.8.0
*
* @param {*} message Message object -- {message: String, error: Bool }
* @return {*}
* @constructor
*/
function ErrorOrNotice(message) {
if (message.error) {
return Error(message);
Expand All @@ -26034,6 +26052,12 @@ var CalderaFormsFieldGroup = function CalderaFormsFieldGroup(props) {

var className = 'form-group cf2-field-group';
className = hasError ? className + ' has-error' : className;

/**
* Render CalderaFormsFieldGroup component
*
* @since 1.8.0
*/
return wp.element.createElement(
'div',
{ className: className },
Expand Down
2 changes: 1 addition & 1 deletion clients/render/build/index.min.js.map

Large diffs are not rendered by default.

100 changes: 61 additions & 39 deletions clients/render/components/CalderaFormsFieldGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {FileInput} from "./Fields/FileInput";
* @constructor
*/
export const CalderaFormsFieldGroup = (props) => {
const {field, onChange, shouldDisable, shouldShow,hasMessage,isError,message,getFieldConfig} = props;
const {field, onChange, shouldDisable, shouldShow, hasMessage, isError, message, getFieldConfig} = props;
const {
type,
outterIdAttr,
Expand All @@ -35,7 +35,7 @@ export const CalderaFormsFieldGroup = (props) => {
}


const hasCaption = field.hasOwnProperty('caption' ) && field.caption.length;
const hasCaption = field.hasOwnProperty('caption') && field.caption.length;
const captionId = `${fieldIdAttr}Caption`;
const hasError = isError || hasMessage && message.error;

Expand All @@ -47,14 +47,14 @@ export const CalderaFormsFieldGroup = (props) => {
* @return {*}
* @constructor
*/
const Inside = () =>{
const Inside = () => {
let className = 'form-control cf2-field';
className = hasError ? className + ' parsley-error' : className;
className = className + ' cf2-' + type;
className = className + ' cf2-' + type;
switch (type) {
case 'file':
const fileProps = FileInput.fieldConfigToProps(getFieldConfig(fieldIdAttr));
return<FileInput
return <FileInput
onChange={onChange}
field={field}
shouldDisable={shouldDisable}
Expand All @@ -65,15 +65,15 @@ export const CalderaFormsFieldGroup = (props) => {
inputProps={fileProps.inputProps}
className={className}
accept={fileProps.accept}
usePreviews={fileProps.usePreviews}
previewHeight={fileProps.previewHeight}
previewWidth={fileProps.previewWidth}
usePreviews={fileProps.usePreviews}
previewHeight={fileProps.previewHeight}
previewWidth={fileProps.previewWidth}
multiple={fileProps.multiple}
multiUploadText={fileProps.multiUploadText}
/>
case'text':
default:
return<Input
return <Input
field={field}
onChange={onChange}
shouldDisable={shouldDisable}
Expand All @@ -85,6 +85,15 @@ export const CalderaFormsFieldGroup = (props) => {
}
};

/**
* Create error markup
*
* @since 1.8.0
*
* @param {*} message Message object -- {message: String, error: Bool }
* @return {*}
* @constructor
*/
function Error(message) {
return <span
className="help-block caldera_ajax_error_block filled"
Expand All @@ -94,8 +103,17 @@ export const CalderaFormsFieldGroup = (props) => {
</span>;
};

function ErrorOrNotice(message) {
if( message.error ){
/**
* Create error or non-error markup
*
* @since 1.8.0
*
* @param {*} message Message object -- {message: String, error: Bool }
* @return {*}
* @constructor
*/
function ErrorOrNotice(message) {
if (message.error) {
return Error(message);
}
return <span
Expand All @@ -108,42 +126,46 @@ export const CalderaFormsFieldGroup = (props) => {

let className = 'form-group cf2-field-group';
className = hasError ? className + ' has-error' : className;
return (

<div className={className}>
<label
className={'control-label'}
htmlFor={fieldIdAttr}
id={`${fieldIdAttr}Label`}
/**
* Render CalderaFormsFieldGroup component
*
* @since 1.8.0
*/
return (
<div className={className}>
<label
className={'control-label'}
htmlFor={fieldIdAttr}
id={`${fieldIdAttr}Label`}
>
{fieldLabel}
</label>
<Inside/>

{hasCaption &&
<span
id={captionId}
className={'help-block'}
>
{fieldLabel}
</label>
<Inside/>

{hasCaption &&
<span
id={captionId}
className={'help-block'}
>
{field.caption}
</span>
}
{isInvalid &&
Error(message)
}

{hasMessage &&
ErrorOrNotice(message)
}

</div>
{field.caption}
</span>
}
{isInvalid &&
Error(message)
}

{hasMessage &&
ErrorOrNotice(message)
}

</div>

);

};



/**
* Prop Type definitions for CalderaFormsFieldGroup component
*
Expand Down

0 comments on commit 71cc344

Please sign in to comment.