diff options
| author | Miquel Sabaté Solà <msabate@suse.com> | 2024-03-20 11:57:02 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <msabate@suse.com> | 2024-03-20 11:57:02 +0100 |
| commit | 37d4967780f5b3dd06bb05337149811d7d7f8788 (patch) | |
| tree | 64623bf68c0e53314c339e87d9273d646f439baa /app/javascript/controllers | |
| parent | c0646186c2049e75ae932966aa0604d712b4f4c6 (diff) | |
| download | operum-37d4967780f5b3dd06bb05337149811d7d7f8788.tar.gz operum-37d4967780f5b3dd06bb05337149811d7d7f8788.zip | |
Handle special characters in "target" completion
Hyphens should be suppressed and underscores are to be taken as pairs
which contain the real value to be picked.
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'app/javascript/controllers')
| -rw-r--r-- | app/javascript/controllers/thing_controller.js | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/app/javascript/controllers/thing_controller.js b/app/javascript/controllers/thing_controller.js index 9c19eb6..ca957ba 100644 --- a/app/javascript/controllers/thing_controller.js +++ b/app/javascript/controllers/thing_controller.js @@ -33,14 +33,30 @@ export default class extends Controller { return; } - const authors = text.split(',').map(function(author) { - return author.split(' ').pop().trim(); - }); - - this.firstPart = authors.join(''); + this.firstPart = text.split(',').map(this.parseAuthor).join(''); this.identifierTarget.value = `${this.firstPart}${this.lastPart}`; } + // Returns the author compressed as expected for "target" autocompletion. + parseAuthor(author) { + // First of all try to match a pair of "_". If these are found, then we have + // to return whatever is in there with no spaces. + let idx = author.indexOf('_'); + + if (idx > -1) { + let idx2 = author.indexOf('_', idx + 1); + if (idx2 > -1) { + return author.substring(idx + 1, idx2).replace(' ', ''); + } + } + + // There was no pair of underscores, let's proceed by picking on the last + // name. + return author + .split(' ').pop().trim() // Pick the last element. + .replace('-', ''); // "Last-Other" => "LastOther" + } + // Update the information we get from the year field so to autocomplete it // into the "target" field if possible. yearUpdate() { |
