Skip to content

Commit

Permalink
MBS-10732: Add collaborator validation to collection form
Browse files Browse the repository at this point in the history
Up until now a user could type in an editor name in the collaborators
field for a collection and try to submit without selecting a result,
leading to an ISE.

The error field is special-cased to remove the margin because otherwise
a margin of over 160px makes it look absurd.

Also, inputName for the autocomplete was incorrect, so this
fixes that.
  • Loading branch information
reosarevok committed May 5, 2020
1 parent df562d1 commit 9e2f8d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/MusicBrainz/Server/Form/Collection.pm
Expand Up @@ -78,4 +78,18 @@ sub validate_type_id {
}
}

sub validate_collaborators {
my $self = shift;

my @collaborators = $self->field('collaborators')->fields;
for my $collaborator (@collaborators) {
my $field = $collaborator->field('id');
if (!(defined $field->value)) {
return $field->add_error(
l('You must select the collaborator(s) before submitting.')
);
}
}
}

1;
Expand Up @@ -100,15 +100,19 @@ const CollectionEditForm = ({collectionTypes, form}: Props) => {
/>
<div className="form-row-text-list">
{collaborators.field.map((collaborator, index) => (
<div className="text-list-row" key={collaborator.html_name}>
<div
className="text-list-row"
id="collaborators-form-list"
key={collaborator.html_name}
>
<Autocomplete
currentSelection={{
id: collaborator.field.id.value,
name: collaborator.field.name.value,
}}
entity="editor"
inputID={'id-' + collaborator.html_name}
inputName={collaborator.html_name}
inputName={collaborator.field.name.html_name}
onChange={(c) => handleCollaboratorChange(c, index)}
>
<input
Expand Down
2 changes: 2 additions & 0 deletions root/static/styles/forms.less
Expand Up @@ -152,6 +152,8 @@ form ul.errors {
margin-left: @form-label-width + @form-margin;
}

#collaborators-form-list ul.errors { margin-left: 0; }

.select-list-row ul.errors {
margin-left: 0;
}
Expand Down

0 comments on commit 9e2f8d0

Please sign in to comment.