Skip to content

Commit

Permalink
add simple validation when choosing Other
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyanwang committed Sep 17, 2020
1 parent 84cd0ed commit 875d384
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions _locales/cy/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,13 @@
"noTenantAlert": {
"message": "Nodwch sefydliad mewn lleoliadau ymestyn",
"description": "Alert presented if no institution has been set"
},
"noTenantShortCodeAlert": {
"message": "Wrth ddewis Arall rhaid i chi nodi cod byr tenant",
"description": "Alert presented if Other institution is selected but no short code is provided"
},
"noTenantRegionAlert": {
"message": "Wrth ddewis Arall rhaid i chi nodi rhanbarth",
"description": "Alert presented if Other institution is selected but no region is provided"
}
}
8 changes: 8 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,13 @@
"noTenantAlert": {
"message": "Please specify an institution in extension settings",
"description": "Alert presented if no institution has been set"
},
"noTenantShortCodeAlert": {
"message": "When selecting Other you must specify a tenant short code",
"description": "Alert presented if Other institution is selected but no short code is provided"
},
"noTenantRegionAlert": {
"message": "When selecting Other you must specify a region",
"description": "Alert presented if Other institution is selected but no region is provided"
}
}
11 changes: 11 additions & 0 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ $(function() {
if ($('#specifyTenant:selected').length > 0) {
var otherTenantCode = $('#tenantCode').val();
var otherTenantRegion = $('#tenantRegion').val();

if (!otherTenantCode.trim()) {
$('#optionsHelp').html('<div class="alert alert-danger">' + chromeOrBrowser().i18n.getMessage('noTenantShortCodeAlert') + '</div>');
return;
}

if (!otherTenantRegion.trim()) {
$('#optionsHelp').html('<div class="alert alert-danger">' + chromeOrBrowser().i18n.getMessage('noTenantRegionAlert') + '</div>');
return;
}

saveActiveTenantAndUpdateStatus(
buildTenant(otherTenantCode, otherTenantRegion)
);
Expand Down

0 comments on commit 875d384

Please sign in to comment.