Sha256: 8068ae7e2b4931aa67844b9c704a17159b6e06246f61be7bbe4d80e9cf3fad50

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

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';
import { isPositiveNumber } from './FormHelpers';

export const NumberInput = ({ formProps, inputProps }) => {
  const [validated, setValidated] = useState();
  const name = inputProps.id.replace(/-/g, ' ');
  return (
    <FormGroup
      {...formProps}
      helperTextInvalid={__('Has to be a positive number')}
      validated={validated}
    >
      <TextInput
        ouiaId={name}
        aria-label={name}
        type="text"
        {...inputProps}
        onChange={newValue => {
          setValidated(
            isPositiveNumber(newValue) || newValue === ''
              ? ValidatedOptions.noval
              : ValidatedOptions.error
          );
          inputProps.onChange(newValue);
        }}
      />
    </FormGroup>
  );
};

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
foreman_remote_execution-13.2.7 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-15.0.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.1.4 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.1.3 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.1.2 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.1.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.1.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.0.2 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.0.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.6 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-14.0.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.5 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.4 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.3 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.2 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.2.0 webpack/JobWizard/steps/form/NumberInput.js