From 875d384266e2aa43ce663cb09230ffbff9ccbd7a Mon Sep 17 00:00:00 2001 From: Nadeem Shabir Date: Thu, 17 Sep 2020 09:42:44 +0100 Subject: [PATCH] add simple validation when choosing Other --- _locales/cy/messages.json | 8 ++++++++ _locales/en/messages.json | 8 ++++++++ js/options.js | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/_locales/cy/messages.json b/_locales/cy/messages.json index 604525f..6003db3 100644 --- a/_locales/cy/messages.json +++ b/_locales/cy/messages.json @@ -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" } } diff --git a/_locales/en/messages.json b/_locales/en/messages.json index ab17d81..1d7f6bf 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -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" } } diff --git a/js/options.js b/js/options.js index 79320a0..b8dc069 100644 --- a/js/options.js +++ b/js/options.js @@ -12,6 +12,17 @@ $(function() { if ($('#specifyTenant:selected').length > 0) { var otherTenantCode = $('#tenantCode').val(); var otherTenantRegion = $('#tenantRegion').val(); + + if (!otherTenantCode.trim()) { + $('#optionsHelp').html('
' + chromeOrBrowser().i18n.getMessage('noTenantShortCodeAlert') + '
'); + return; + } + + if (!otherTenantRegion.trim()) { + $('#optionsHelp').html('
' + chromeOrBrowser().i18n.getMessage('noTenantRegionAlert') + '
'); + return; + } + saveActiveTenantAndUpdateStatus( buildTenant(otherTenantCode, otherTenantRegion) );