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

Change validation rules in new participant form #377

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions frontend/src/components/Participants.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,14 @@ import {
minLength,
maxLength,
email,
numeric,
alpha,
alphaNum
numeric
} from 'vuelidate/lib/validators';
import _ from 'lodash';
import {
slackNickValidator,
gitHubUsernameValidator
} from '../helpers/validation';
Comment on lines +189 to +192
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a neat trick to get around it - kudos!


export default {
data() {
return {
Expand Down Expand Up @@ -223,7 +226,7 @@ export default {
},
github: {
required,
alphaNum,
gitHubUsernameValidator,
githubExists(value) {
return this.editParticipant
? true
Expand All @@ -234,18 +237,16 @@ export default {
},
first_name: {
required,
alpha,
minLength: minLength(3),
maxLength: maxLength(25)
},
last_name: {
required,
alpha,
minLength: minLength(3),
maxLength: maxLength(25)
},
slack: {
alphaNum,
slackNickValidator,
minLength: minLength(3),
maxLength: maxLength(25)
},
Expand Down Expand Up @@ -383,8 +384,8 @@ export default {
const errors = [];

if (!this.$v.form.github.$dirty) return errors;
!this.$v.form.github.alphaNum &&
errors.push('You used characters which are not permitted');
!this.$v.form.github.gitHubUsernameValidator &&
errors.push('Invalid username');
!this.$v.form.github.required && errors.push('This field is required');
!this.$v.form.github.githubExists && errors.push('User already exists');
return errors;
Expand All @@ -393,8 +394,6 @@ export default {
const errors = [];

if (!this.$v.form.first_name.$dirty) return errors;
!this.$v.form.first_name.alpha &&
errors.push('You used characters which are not permitted');
!this.$v.form.first_name.required &&
errors.push('This field is required');
!this.$v.form.first_name.minLength && errors.push('Name is too short');
Expand All @@ -405,8 +404,6 @@ export default {
const errors = [];

if (!this.$v.form.last_name.$dirty) return errors;
!this.$v.form.last_name.alpha &&
errors.push('You used characters which are not permitted');
!this.$v.form.last_name.required && errors.push('This field is required');
!this.$v.form.last_name.minLength &&
errors.push('Last name is too short');
Expand All @@ -417,8 +414,7 @@ export default {
const errors = [];

if (!this.$v.form.slack.$dirty) return errors;
!this.$v.form.slack.alphaNum &&
errors.push('You used characters which are not permitted');
!this.$v.form.slack.slackNickValidator && errors.push('Invalid nick');
!this.$v.form.slack.minLength && errors.push('Nick is too short');
!this.$v.form.slack.maxLength && errors.push('Nick is too long');
return errors;
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/helpers/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { helpers } from 'vuelidate/lib/validators';

export const slackNickValidator = helpers.regex(
'slackNickValidator',
/^[0-9A-Za-ząćęłńóśźżĄĆĘŁŃÓŚŹŻ,.';\-_/()[\]{}]*$/
);

export const gitHubUsernameValidator = helpers.regex(
'gitHubUsernameValidator',
/^[0-9A-Za-z][0-9A-Za-z-]*[0-9A-Za-z]$/
Copy link
Contributor

@stanislawK stanislawK May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever You want match the character - literally with regex, it is safer to escape it and use "\-" instead of "-".

Copy link
Contributor Author

@Marce1ina Marce1ina May 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stanislawK I have removed it as it causes lint failure: error: Unnecessary escape character: \- (no-useless-escape) at src/helpers/validation.js:10:26 and it seems fair, please check https://stackoverflow.com/questions/9589074/regex-should-hyphens-be-escaped for reference.

);