Fixes labels being serialized incorrectly, automates tag serialization

This commit is contained in:
Anton Stubenbord
2023-02-06 17:30:00 +01:00
parent 4aa98c6fa9
commit 348eb30e1a
12 changed files with 175 additions and 145 deletions

View File

@@ -54,8 +54,9 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
@override
void initState() {
super.initState();
_enableMatchFormField =
widget.initialValue?.matchingAlgorithm != MatchingAlgorithm.auto;
_enableMatchFormField = (widget.initialValue?.matchingAlgorithm ??
MatchingAlgorithm.defaultValue) !=
MatchingAlgorithm.auto;
}
@override
@@ -83,8 +84,9 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
),
FormBuilderDropdown<int?>(
name: Label.matchingAlgorithmKey,
initialValue: widget.initialValue?.matchingAlgorithm.value ??
MatchingAlgorithm.auto.value,
initialValue: (widget.initialValue?.matchingAlgorithm ??
MatchingAlgorithm.defaultValue)
.value,
decoration: InputDecoration(
labelText: S.of(context).labelMatchingAlgorithmPropertyLabel,
errorText: _errors[Label.matchingAlgorithmKey],
@@ -99,7 +101,8 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
.map(
(algo) => DropdownMenuItem<int?>(
child: Text(
translateMatchingAlgorithmDescription(context, algo)),
translateMatchingAlgorithmDescription(context, algo),
),
value: algo.value,
),
)
@@ -139,8 +142,8 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
// If auto is selected, the match will be removed.
mergedJson[Label.matchKey] = '';
}
final createdLabel = await widget.submitButtonConfig
.onSubmit(widget.fromJsonT(mergedJson));
final parsed = widget.fromJsonT(mergedJson);
final createdLabel = await widget.submitButtonConfig.onSubmit(parsed);
Navigator.pop(context, createdLabel);
} on PaperlessServerException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);