import React, { useState } from 'react' import { useSelector } from 'react-redux' import TagSVG from './images/tag.svg?react' import { getFormTagsExceptForIdSelector } from '@epicformbuilder/admin/data' export default function DataTag({ id, tag, onChange }) { const tags = useSelector( store => getFormTagsExceptForIdSelector( store, id ) ) const [ wrongCharacterError, setWrongCharacterError ] = useState( false ) const testValue = value => /^[\d\w-_]*$/.test(value) return (
Data tag
{ tags.includes( tag ) && Data tag must be unique to the Form } { wrongCharacterError && Only latin letters, 0 to 9 digits and -, _ symbols are allowed } { if (testValue(e.target.value)) { setWrongCharacterError(false) onChange(e) } else { setWrongCharacterError(true) } }} />
Tag must have a unique name through the whole form and be of latin letters, 0-9 digits and -, _ characters only
) }