Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBS-10732: Add collaborator validation to collection form #1496

Merged
merged 1 commit into from May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/MusicBrainz/Server/Form/Collection.pm
Expand Up @@ -78,4 +78,32 @@ sub validate_type_id {
}
}

sub validate_collaborators {
my $self = shift;

my @collaborators = $self->field('collaborators')->fields;
my $is_valid = 1;
for my $collaborator (@collaborators) {
my $id_field = $collaborator->field('id');
my $name_field = $collaborator->field('name');
if (defined $name_field->value && !(defined $id_field->value)) {
yvanzo marked this conversation as resolved.
Show resolved Hide resolved
my $editor = $self->ctx->model('Editor')->get_by_name($name_field->value);
if (defined $editor) {
$id_field->add_error(
l('To add “{editor}” as a collaborator, please select them from the dropdown.',
{editor => $name_field->value})
);
} else {
$id_field->add_error(
l('Editor “{editor}” does not exist.',
{editor => $name_field->value})
);
}
$is_valid = 0;
}
}

return $is_valid;
}

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