Add feedback on incorrect resource input.
continuous-integration/drone/push Build is running
Details
continuous-integration/drone/push Build is running
Details
Fixes: https://github.com/happyDomain/happydomain/issues/12
This commit is contained in:
parent
0bdb1c4c04
commit
cd29ec9eb0
|
@ -10,6 +10,8 @@
|
|||
InputType,
|
||||
} from 'sveltestrap/src/Input.d';
|
||||
|
||||
import { t } from '$lib/translations';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
export let edit = false;
|
||||
|
@ -38,6 +40,36 @@
|
|||
inputmin = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function checkBase64(val: string): bool {
|
||||
try {
|
||||
atob(val);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let feedback: string|null = null;
|
||||
$: {
|
||||
if (inputmax && value > inputmax) {
|
||||
feedback = t.get('errors.too-high', {max: inputmax});
|
||||
} else if (inputmin && value < inputmin) {
|
||||
feedback = t.get('errors.too-low', {min: inputmin});
|
||||
} else if (specs.type && (specs.type === "[]uint8" || specs.type === "[]byte") && !checkBase64(value)) {
|
||||
if (checkBase64(value+"==")) {
|
||||
feedback = t.get("errors.base64") + " " + t.get("errors.suggestion", {suggestion: `${value}==`});
|
||||
} else if (checkBase64(value+"=")) {
|
||||
feedback = t.get("errors.base64") + " " + t.get("errors.suggestion", {suggestion: `${value}=`});
|
||||
} else if (checkBase64(value+"a")) {
|
||||
feedback = t.get("errors.base64") + " " + t.get("errors.base64-unfinished");
|
||||
} else {
|
||||
feedback = t.get("errors.base64") + " " + t.get("errors.base64-illegal-char");
|
||||
}
|
||||
} else {
|
||||
feedback = null;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<InputGroup size="sm" {...$$restProps}>
|
||||
|
@ -59,6 +91,8 @@
|
|||
id={'spec-' + index + '-' + specs.id}
|
||||
type={inputtype}
|
||||
class="fw-bold"
|
||||
{feedback}
|
||||
invalid={feedback !== null}
|
||||
min={inputmin}
|
||||
max={inputmax}
|
||||
placeholder={specs.placeholder}
|
||||
|
|
|
@ -177,7 +177,13 @@
|
|||
},
|
||||
"settings-change": "Unable to change your settings",
|
||||
"account-no-auth": "You're using happyDomain without authentication. You cannot manage other account properties.",
|
||||
"domain-all-imported": "This account on {{provider}} doesn't have any more domain to import."
|
||||
"domain-all-imported": "This account on {{provider}} doesn't have any more domain to import.",
|
||||
"too-high": "Number too high, max: {{max}}",
|
||||
"too-low": "Number too low, min: {{min}}",
|
||||
"base64": "Invalid base64 string.",
|
||||
"base64-illegal-char": "Illegal character used.",
|
||||
"base64-unfinished": "Unfinised string.",
|
||||
"suggestion": "Did you mean: {{suggestion}}"
|
||||
},
|
||||
"menu": {
|
||||
"my-domains": "My domains",
|
||||
|
|
|
@ -171,7 +171,13 @@
|
|||
"settings-change": "Impossible de changer vos paramètres",
|
||||
"account-no-auth": "Vous utilisez happyDomain sans authentification. Vous ne pouvez pas changer d'autre paramètre de votre compte.",
|
||||
"domain-all-imported": "Ce compte sur {{provider}} ne contient plus aucun domaine à importer.",
|
||||
"provider-delete": "Une erreur s'est produite lors de la suppression de la référence au fournisseur d'hébergement"
|
||||
"provider-delete": "Une erreur s'est produite lors de la suppression de la référence au fournisseur d'hébergement",
|
||||
"too-high": "Nombre trop grand, max: {{max}}",
|
||||
"too-low": "Nombre trop petit, min: {{min}}",
|
||||
"base64": "Chaîne base64 invalide.",
|
||||
"base64-illegal-char": "Charactère incorrect utilisé.",
|
||||
"base64-unfinished": "La chaîne est incomplète.",
|
||||
"suggestion": "Voulez-vous dire: {{suggestion}}"
|
||||
},
|
||||
"menu": {
|
||||
"my-domains": "Mes domaines",
|
||||
|
|
Loading…
Reference in New Issue