fix javascript bug/malfunction

This commit is contained in:
Gregory Trullemans 2024-01-23 18:52:57 +01:00
parent c85dd9e6f2
commit 08132787f8
1 changed files with 39 additions and 23 deletions

View File

@ -99,7 +99,7 @@
</div>
</div>
<div class="form-group row">
<label class="col-12 text-center text-danger" id="note_info"><b>Merci de mettre une information complémentaire.</b></label>
<label class="col-12 text-center text-danger" id="note_info"><b>Merci de donner des détails concernant les scores.</b></label>
</div>
<div class="form-group row ">
<label for="id_information" class="col-4 col-sm-2 col-md-4 col-lg-4 col-xl-3 col-form-label">Informations <span class="text-danger" id="span_info_required"><b>*</b></span></label>
@ -121,49 +121,65 @@
{% block footerscript %}
<script type="text/javascript" >
$().ready(function(){
$("#note_info").hide();
$("#span_info_required").hide();
function show_or_hide_info()
function are_informations_too_short()
{
alert($('#id_informations').val().length);
if($('#id_informations').val().length < 10)
$("#note_info").show();
return true;
else
$("#note_info").hide();
return false;
};
show_or_hide_info();
function check_form_values()
{
var test = check_value_lower($('#id_mindstate').val());
test = test || check_value_lower($('#id_sleep').val());
test = test || check_value_upper($('#id_stress').val());
test = test || check_value_upper($('#id_fatigue').val());
test = test || check_value_upper($('#id_muscle_soreness').val());
return test
}
function check_value_lower(value)
{
if(value <= 5) {
show_or_hide_info();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
if(value <= 5)
return true
else
return false
};
function check_value_upper(value)
{
if(value >= 5) {
show_or_hide_info();
if(value >= 5)
return true
else
return false
};
$('#id_mindstate, #id_sleep, #id_stress, #id_fatigue, #id_muscle_soreness').on('change', function(){
test = check_form_values();
if(test) {
$("#note_info").show();
$("#span_info_required").show();
} else {
$("#note_info").hide();
$("#span_info_required").hide();
}
}
$('#id_mindstate, #id_sleep').on('change', function(){
check_value_lower($(this).val());
});
$('#id_stress, #id_fatigue, #id_muscle_soreness').on('change', function(){
check_value_upper($(this).val());
});
$('#id_informations').on("keyup", function(){
test = check_form_values();
$('#id_informations').on("keyup", show_or_hide_info());
test = test && are_informations_too_short()
if(test)
$("#note_info").show();
else
$("#note_info").hide();
});
const csrf_token = "{{ csrf_token|escapejs }}";
const gymnast_lookup = "{% url 'gymnast_lookup' %}";