Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions assets/src/js/admin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ document.addEventListener('DOMContentLoaded', () => {
const options = [];

inputs.forEach(function (input) {
input = plausible.validateInput(input);

options.push({name: input.name, value: input.value});
});

Expand All @@ -158,6 +160,21 @@ document.addEventListener('DOMContentLoaded', () => {
plausible.ajax(form, button);
},

/**
* Currently only validates the domain_name input, but can be used in the future for other custom input validations.
*
* @param input
* @returns {*}
*/
validateInput: function (input) {
// Strip http(s)://(www.) from domain_name before sending it.
if (input.name === 'domain_name' && input.value.match(/^(https?:\/\/)?(www.)?/).length > 0) {
input.value = input.value.replace(/^(https?:\/\/)?(www.)?/, '');
}

return input;
},

/**
* Save Options on Next click for API Token and Domain Name slides.
*
Expand All @@ -175,6 +192,8 @@ document.addEventListener('DOMContentLoaded', () => {
let options = [];

for (let input of inputs) {
input = plausible.validateInput(input);

options.push({name: input.name, value: input.value});
}

Expand Down
Loading