Sha256: b3cac3435b4a6c3946c0b4552e82242a44b11e60f08abf63c3c0798a03a670fd

Contents?: true

Size: 1.04 KB

Versions: 55

Compression:

Stored size: 1.04 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
        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

55 entries across 55 versions & 1 rubygems

Version Path
foreman_remote_execution-12.0.7 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-10.1.3 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-13.0.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-12.0.5 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-12.0.4 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-12.0.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-12.0.2 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-11.1.3 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-10.1.2 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-12.0.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-10.1.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-11.1.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-11.1.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-10.1.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-8.3.3 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-8.3.2 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-11.0.0 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-10.0.7 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-8.3.1 webpack/JobWizard/steps/form/NumberInput.js
foreman_remote_execution-10.0.6 webpack/JobWizard/steps/form/NumberInput.js