webpack/helpers/formFieldsHelper.js in foreman_openscap-5.1.0 vs webpack/helpers/formFieldsHelper.js in foreman_openscap-5.1.1
- old
+ new
@@ -1,11 +1,60 @@
import React from 'react';
import PropTypes from 'prop-types';
-import { FormGroup, TextInput } from '@patternfly/react-core';
+import {
+ FormGroup,
+ TextInput,
+ TextArea,
+ FormSelect,
+ FormSelectOption,
+} from '@patternfly/react-core';
import { ExclamationCircleIcon } from '@patternfly/react-icons';
+export const SelectField = props => {
+ const { selectItems, field, form } = props;
+ const fieldProps = wrapFieldProps(field);
+
+ const valid = shouldValidate(form, field.name);
+
+ return (
+ <FormGroup
+ label={props.label}
+ isRequired={props.isRequired}
+ helperTextInvalid={form.errors[field.name]}
+ helperTextInvalidIcon={<ExclamationCircleIcon />}
+ validated={valid}
+ >
+ <FormSelect
+ {...fieldProps}
+ className="without_select2"
+ aria-label={fieldProps.name}
+ validated={valid}
+ isDisabled={form.isSubmitting}
+ >
+ <FormSelectOption key={0} value="" label={props.blankLabel} />
+ {selectItems.map((item, idx) => (
+ <FormSelectOption key={idx + 1} value={item.id} label={item.name} />
+ ))}
+ </FormSelect>
+ </FormGroup>
+ );
+};
+
+SelectField.propTypes = {
+ selectItems: PropTypes.array,
+ label: PropTypes.string.isRequired,
+ isRequired: PropTypes.bool,
+ field: PropTypes.object.isRequired,
+ form: PropTypes.object.isRequired,
+ blankLabel: PropTypes.string.isRequired,
+};
+SelectField.defaultProps = {
+ selectItems: [],
+ isRequired: false,
+};
+
const wrapFieldProps = fieldProps => {
const { onChange } = fieldProps;
// modify onChange args to correctly wire formik with pf4 input handlers
const wrappedOnChange = (value, event) => {
onChange(event);
@@ -59,5 +108,6 @@
return Subcomponent;
};
export const TextField = fieldWithHandlers(TextInput);
+export const TextAreaField = fieldWithHandlers(TextArea);