Sha256: ba5d2d6ebcb5ad4a79ada0e92204586a7b535bde7f1e386fe2506354f30033b1

Contents?: true

Size: 922 Bytes

Versions: 5

Compression:

Stored size: 922 Bytes

Contents

import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { FormGroup, TextInput, ValidatedOptions } from '@patternfly/react-core';
import { translate as __ } from 'foremanReact/common/I18n';

export const NumberInput = ({ formProps, inputProps }) => {
  const [validated, setValidated] = useState();
  return (
    <FormGroup
      {...formProps}
      helperTextInvalid={__('Has to be a number')}
      validated={validated}
    >
      <TextInput
        type="text"
        {...inputProps}
        onChange={newValue => {
          setValidated(
            /^\d+$/.test(newValue) || newValue === ''
              ? ValidatedOptions.noval
              : ValidatedOptions.error
          );
          inputProps.onChange(newValue);
        }}
      />
    </FormGroup>
  );
};

NumberInput.propTypes = {
  formProps: PropTypes.object.isRequired,
  inputProps: PropTypes.object.isRequired,
};

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_remote_execution-4.5.5 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-4.5.4 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-4.7.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-4.5.3 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-4.5.2 webpack/JobWizard/steps/form/NumberInput.js