From 32027f09d6c4b89398ea6d965cda5906255b2703 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 27 Jul 2021 05:21:05 +0530 Subject: [PATCH] refine link name placeholder suggestion and provide a more descriptive error message --- www/common/drive-ui.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 82cabec8f..15558cf18 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -2745,9 +2745,15 @@ define([ url = h('input#cp-app-drive-link-url', { type: 'url', autocomplete: 'off', placeholder: Messages.form_input_ph_url }), warning, ]); + + var protocolPattern = /https*:\/\//; + var fragmentPattern = /#.*$/; var setNamePlaceholder = function (val) { - val = val.replace(/https*:\/\//, '').replace(/#.*$/, '').slice(0, 16); - name.setAttribute('placeholder', val) + var temp = val.replace(protocolPattern, '').replace(fragmentPattern, '').trim().slice(0, 48); + if (!protocolPattern.test(val) || !temp) { + temp = Messages.fm_link_name_placeholder; + } + name.setAttribute('placeholder', temp); }; var $warning = $(warning).hide(); @@ -2778,7 +2784,7 @@ define([ if (!n || !u) { return true; } if (!Util.isValidURL(u)) { // XXX 4.10.0 add style for invalid input? input:invalid - UI.warn(Messages.error); + UI.warn(Messages.fm_link_invalid); return true; } manager.addLink(currentPath, {