diff options
Diffstat (limited to 'addons/website/static/src')
| -rw-r--r-- | addons/website/static/src/js/editor/snippets.options.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 5225c57b249..abd32016131 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -159,7 +159,7 @@ const FontFamilyPickerUserValueWidget = SelectUserValueWidget.extend({ { text: _t("Save & Reload"), classes: 'btn-primary', - click: () => { + click: async () => { const inputEl = dialog.el.querySelector('.o_input_google_font'); // if font page link (what is expected) let m = inputEl.value.match(/\bspecimen\/([\w+]+)/); @@ -171,6 +171,24 @@ const FontFamilyPickerUserValueWidget = SelectUserValueWidget.extend({ return; } } + + let isValidFamily = false; + + try { + const result = await fetch("https://fonts.googleapis.com/css?family=" + m[1], {method: 'HEAD'}); + // Google fonts server returns a 400 status code if family is not valid. + if (result.ok) { + isValidFamily = true; + } + } catch (error) { + console.error(error); + } + + if (!isValidFamily) { + inputEl.classList.add('is-invalid'); + return; + } + const font = m[1].replace(/\+/g, ' '); this.googleFonts.push(font); this.trigger_up('google_fonts_custo_request', { |
