- validate={getValidation(vocabulary)} />);
-
-const PropertyKeyInput = ({ input, meta, vocabulary }: WrappedFieldProps & VocabularyProp) =>
- <Autocomplete
- value={input.value}
- onChange={input.onChange}
- onBlur={handleBlur(input)}
- label='Key'
- suggestions={getSuggestions(input.value, vocabulary)}
- items={ITEMS_PLACEHOLDER}
- onSelect={input.onChange}
- renderSuggestion={identity}
- error={hasError(meta)}
- helperText={getErrorMsg(meta)}
- />;
+ validate={skipValidation ? undefined : getValidation(vocabulary)} />
+ </span>
+);
+
+const PropertyKeyInput = ({ vocabulary, ...props }: WrappedFieldProps & VocabularyProp & { clearPropertyKeyOnSelect?: boolean }) =>
+ <FormName children={data => (
+ <Autocomplete
+ {...buildProps(props)}
+ label='Key'
+ suggestions={getSuggestions(props.input.value, vocabulary)}
+ renderSuggestion={
+ (s: PropFieldSuggestion) => s.synonyms && s.synonyms.length > 0
+ ? `${s.label} (${s.synonyms.join('; ')})`
+ : s.label
+ }
+ onFocus={() => {
+ if (props.clearPropertyKeyOnSelect && props.input.value) {
+ props.meta.dispatch(reset(props.meta.form));
+ }
+ }}
+ onSelect={handleSelect(PROPERTY_KEY_FIELD_ID, data.form, props.input, props.meta)}
+ onBlur={() => {
+ // Case-insensitive search for the key in the vocabulary
+ const foundKeyID = getTagKeyID(props.input.value, vocabulary);
+ if (foundKeyID !== '') {
+ props.input.value = getTagKeyLabel(foundKeyID, vocabulary);
+ }
+ handleBlur(PROPERTY_KEY_FIELD_ID, data.form, props.meta, props.input, foundKeyID)();
+ }}
+ onChange={(e: ChangeEvent<HTMLInputElement>) => {
+ const newValue = e.currentTarget.value;
+ handleChange(data.form, props.input, props.meta, newValue);
+ }}
+ />
+ )} />;