Skip to content

Commit

Permalink
#2766 set required and disabled props more intelligently
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock committed Oct 19, 2018
1 parent 51184d1 commit f449034
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
44 changes: 29 additions & 15 deletions clients/render/build/index.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -23708,11 +23708,14 @@ module.exports = document && document.documentElement;

"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return CalderaFormsFieldGroup; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_react__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_prop_types__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__CalderaFormsFieldRender__ = __webpack_require__(707);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_extends__ = __webpack_require__(36);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_extends___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_extends__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_react___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_react__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_prop_types__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_prop_types___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_prop_types__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__CalderaFormsFieldRender__ = __webpack_require__(707);




Expand Down Expand Up @@ -23744,8 +23747,20 @@ var CalderaFormsFieldGroup = function CalderaFormsFieldGroup(props) {


if (!shouldShow) {
return wp.element.createElement(__WEBPACK_IMPORTED_MODULE_0_react__["Fragment"], null);
return wp.element.createElement(__WEBPACK_IMPORTED_MODULE_1_react__["Fragment"], null);
}
var propsThatDoNotUseAnEquals = {};
if (shouldDisable) {
propsThatDoNotUseAnEquals.disabled = true;
} else {
propsThatDoNotUseAnEquals.disabled = false;
}
if (required) {
propsThatDoNotUseAnEquals.required = true;
} else {
propsThatDoNotUseAnEquals.required = false;
}

return wp.element.createElement(
'div',
{ className: 'form-group cf2-field-group' },
Expand All @@ -23757,16 +23772,15 @@ var CalderaFormsFieldGroup = function CalderaFormsFieldGroup(props) {
},
fieldLabel
),
wp.element.createElement('input', {
type: type,
disabled: shouldDisable,
wp.element.createElement('input', __WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_extends___default()({
type: type
}, propsThatDoNotUseAnEquals, {
value: fieldValue,
required: required,
className: 'form-control',
id: fieldIdAttr,
placeholder: fieldPlaceHolder,
onChange: onChange
})
}))
);
};

Expand All @@ -23778,10 +23792,10 @@ var CalderaFormsFieldGroup = function CalderaFormsFieldGroup(props) {
* @type {{field: *, onChange: (e|*), shouldShow: *, shouldDisable: *}}
*/
CalderaFormsFieldGroup.propTypes = {
field: __WEBPACK_IMPORTED_MODULE_2__CalderaFormsFieldRender__["a" /* CalderaFormsFieldPropType */],
onChange: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.func.isRequired,
shouldShow: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool,
shouldDisable: __WEBPACK_IMPORTED_MODULE_1_prop_types___default.a.bool
field: __WEBPACK_IMPORTED_MODULE_3__CalderaFormsFieldRender__["a" /* CalderaFormsFieldPropType */],
onChange: __WEBPACK_IMPORTED_MODULE_2_prop_types___default.a.func.isRequired,
shouldShow: __WEBPACK_IMPORTED_MODULE_2_prop_types___default.a.bool,
shouldDisable: __WEBPACK_IMPORTED_MODULE_2_prop_types___default.a.bool
};

/**
Expand Down
2 changes: 1 addition & 1 deletion clients/render/build/index.min.js.map

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions clients/render/components/CalderaFormsFieldGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ export const CalderaFormsFieldGroup = (props) => {
if (!shouldShow) {
return <Fragment/>;
}
const propsThatDoNotUseAnEquals = {};
if (shouldDisable) {
propsThatDoNotUseAnEquals.disabled = true;
} else {
propsThatDoNotUseAnEquals.disabled = false;
}
if (required) {
propsThatDoNotUseAnEquals.required = true;
} else {
propsThatDoNotUseAnEquals.required = false;
}

return (

<div className={'form-group cf2-field-group'}>
Expand All @@ -40,9 +52,8 @@ export const CalderaFormsFieldGroup = (props) => {
</label>
<input
type={type}
disabled={shouldDisable}
{...propsThatDoNotUseAnEquals}
value={fieldValue}
required={required}
className={'form-control'}
id={fieldIdAttr}
placeholder={fieldPlaceHolder}
Expand Down
1 change: 0 additions & 1 deletion clients/tests/unit/render/CalderaFormsFieldGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('CalderaFormsFieldGroup component', () => {
...fieldConfig,
required: true
}}
shouldDiable={true}
/>);
const testInstance = testRenderer.root;

Expand Down

0 comments on commit f449034

Please sign in to comment.