suggestions={getSuggestions(props.input.value, vocabulary)}
onSelect={handleSelect(props.input, props.meta)}
{...buildProps(props)}
+ onBlur={handleBlur(props.meta, props.input, vocabulary)}
/>;
const getValidation = memoize(
return ret;
};
+const getTagKeyID = (tagKeyLabel:string, vocabulary: Vocabulary) =>
+ Object.keys(vocabulary.tags).find(
+ k => vocabulary.tags[k].labels.find(
+ l => l.label === tagKeyLabel) !== undefined) || '';
+
+// Attempts to match a manually typed key label with a key ID, when the user
+// doesn't select the key from the suggestions list.
+const handleBlur = (
+ { dispatch }: WrappedFieldMetaProps,
+ { onBlur, value }: WrappedFieldInputProps,
+ vocabulary: Vocabulary) =>
+ () => {
+ dispatch(change(COLLECTION_TAG_FORM_NAME, PROPERTY_KEY_FIELD_ID, getTagKeyID(value, vocabulary)));
+ onBlur(value);
+ };
+
+// When selecting a property key, save its ID for later usage.
const handleSelect = (
{ onChange }: WrappedFieldInputProps,
{ dispatch }: WrappedFieldMetaProps) => {
suggestions={getSuggestions(props.input.value, propertyKey, vocabulary)}
onSelect={handleSelect(props.input, props.meta)}
{...buildProps(props)}
+ onBlur={handleBlur(props.meta, props.input, vocabulary, propertyKey)}
/>;
const getValidation = (props: PropertyValueFieldProps) =>
return ret;
};
+const getTagValueID = (tagKeyID:string, tagValueLabel:string, vocabulary: Vocabulary) =>
+ (tagKeyID && vocabulary.tags[tagKeyID] && vocabulary.tags[tagKeyID].values)
+ ? Object.keys(vocabulary.tags[tagKeyID].values!).find(
+ k => vocabulary.tags[tagKeyID].values![k].labels.find(
+ l => l.label === tagValueLabel) !== undefined) || ''
+ : '';
+
+// Attempts to match a manually typed value label with a value ID, when the user
+// doesn't select the value from the suggestions list.
+const handleBlur = (
+ { dispatch }: WrappedFieldMetaProps,
+ { onBlur, value }: WrappedFieldInputProps,
+ vocabulary: Vocabulary,
+ tagKeyID: string) =>
+ () => {
+ dispatch(change(COLLECTION_TAG_FORM_NAME, PROPERTY_VALUE_FIELD_ID, getTagValueID(tagKeyID, value, vocabulary)));
+ onBlur(value);
+ };
+
+// When selecting a property value, save its ID for later usage.
const handleSelect = (
{ onChange }: WrappedFieldInputProps,
{ dispatch }: WrappedFieldMetaProps) => {