feat: Settings: password input with hide/show options

This commit is contained in:
slawkens 2025-02-02 21:55:16 +01:00
parent 19686725dc
commit 4fda4f643b
3 changed files with 32 additions and 1 deletions

View File

@ -348,7 +348,7 @@ return [
],
'database_password' => [
'name' => 'Database Password',
'type' => 'text',
'type' => 'password',
'default' => '',
'show_if' => [
'database_overwrite', '=', 'true'

View File

@ -247,7 +247,15 @@ class Settings implements \ArrayAccess
$min = $max = $step = '';
}
if ($setting['type'] === 'password') {
echo '<div class="input-group" id="show-hide-' . $key . '">';
}
echo '<input class="form-control" type="' . $setting['type'] . '" name="settings[' . $key . ']" value="' . ($settingsDb[$key] ?? ($setting['default'] ?? '')) . '" id="' . $key . '"' . $min . $max . $step . '/>';
if ($setting['type'] === 'password') {
echo '<div class="input-group-append input-group-text"><a href=""><i class="fas fa-eye-slash" ></i></a></div></div>';
}
}
else if($setting['type'] === 'textarea') {

View File

@ -109,3 +109,26 @@
});
});
</script>
<script>
{% for key, value in settings %}
{% if value.type == 'password' %}
$(function () {
$('#show-hide-{{ key}} a').on('click', function(event) {
event.preventDefault();
const $showHideIcon = $('#show-hide-{{ key}} i');
const $showHideInput = $('#show-hide-{{ key }} input');
if($showHideInput.attr('type') === 'text'){
$showHideInput.attr('type', 'password');
$showHideIcon.addClass('fa-eye-slash');
$showHideIcon.removeClass('fa-eye');
}else if($showHideInput.attr("type") === 'password'){
$showHideInput.attr('type', 'text');
$showHideIcon.removeClass('fa-eye-slash');
$showHideIcon.addClass('fa-eye');
}
});
});
{% endif %}
{% endfor %}
</script>