import { forwardRef } from 'react'; import { useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { FormControl, FormField, FormItem, FormLabel, FormMessage, } from './ui/form'; import { Input, InputProps } from './ui/input'; interface IProps { value?: string | undefined; onChange?: (val: string | undefined) => void; } export const DelimiterInput = forwardRef( ({ value, onChange, maxLength, defaultValue, ...props }, ref) => { const nextValue = value ?.replaceAll('\n', '\\n') .replaceAll('\t', '\\t') .replaceAll('\r', '\\r'); const handleInputChange = (e: React.ChangeEvent) => { const val = e.target.value; const nextValue = val .replaceAll('\\n', '\n') .replaceAll('\\t', '\t') .replaceAll('\\r', '\r'); onChange?.(nextValue); }; return ( ); }, ); export function DelimiterFormField() { const { t } = useTranslation(); const form = useFormContext(); return ( { if (typeof field.value === 'undefined') { // default value set form.setValue('parser_config.delimiter', '\n'); } return (
{t('knowledgeDetails.delimiter')}
); }} /> ); }