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