Made JavaScript-Magic for some fields.

This commit is contained in:
2018-01-18 14:46:53 +01:00
parent 14f18b2333
commit f5d73d556e
6 changed files with 85 additions and 26 deletions

View File

@@ -86,7 +86,7 @@ MODE_CHOICES = ChoiceSet([
SPORT_CHOICES = ChoiceSet([
('W', _(u'Wanderung')),
('S', _(u'Skitour')),
('S', _(u'Ski')),
('M', _(u'Mountainbike')),
('K', _(u'Klettern')),
('B', _(u'Bergsteigen')),

View File

@@ -123,7 +123,7 @@ class ModeForm(EventCreateForm):
ski_lift = forms.BooleanField(required=False,
label=_(u'Skiliftbenutzung'),
help_text=_(u'Relevant für die Kostenberechnung'),
help_text=_(u'Relevant für die Kostenberechnung bei Skitouren/-kursen'),
)
level = forms.ChoiceField(choices=choices.LEVEL_CHOICES,

View File

@@ -2,6 +2,10 @@
{% load i18n %}
{% load bootstrap3 %}
{% block head-additional %}
{% include 'dav_events/event_create/includes/select_other.html' %}
{% endblock head-additional %}
{% block form-fields-visible %}
<div class="row">
<div class="col-sm-6">

View File

@@ -2,6 +2,34 @@
{% load i18n %}
{% load bootstrap3 %}
{% block head-additional %}
<script type="text/javascript">
function add_sport_handler() {
var elements = $("input[name=sport]");
for(var i = 0 ; i < elements.length ; i++) {
elements[i].onclick = function(){ sport_handler(); };
}
}
function sport_handler() {
var e = $("#id_ski_lift");
if(e != null) {
var sport = $("input[name=sport]:checked").val();
if(sport == "S") {
e.prop("disabled", false);
} else {
e.prop("disabled", true);
}
}
}
$(document).ready(function(){
add_sport_handler();
sport_handler();
});
</script>
{% endblock head-additional %}
{% block form-fields-visible %}
<div class="row">
<div class="col-sm-4">

View File

@@ -10,47 +10,48 @@
var show_goals = 2;
function setupTopicsAndGoals() {
var e;
for(var i = 1 ; i <= max_topics ; i++) {
topic_block = $("#block_topic_" + i);
if(topic_block != null) {
e = $("#block_topic_" + i);
if(e != null) {
if(i <= show_topics) {
if(topic_block.css('display') == 'none')
topic_block.slideDown();
if(e.css("display") == 'none')
e.slideDown();
} else {
//if(topic_block.css('display') != 'none')
// topic_block.slideUp();
topic_block.hide();
//if(e.css("display") != 'none')
// e.slideUp();
e.hide();
}
}
}
for(var i = 1 ; i <= max_goals ; i++) {
goal_block = $("#block_goal_" + i);
if(goal_block != null) {
e = $("#block_goal_" + i);
if(e != null) {
if(i <= show_goals) {
if(goal_block.css('display') == 'none')
goal_block.slideDown();
if(e.css("display") == 'none')
e.slideDown();
} else {
//if(goal_block.css('display') != 'none')
// goal_block.slideUp();
goal_block.hide();
//if(e.css("display") != 'none')
// e.slideUp();
e.hide();
}
}
}
//button = $("#button_add_topic");
button = document.getElementById("button_add_topic");
if(button != null) {
//e = $("#button_add_topic");
e = document.getElementById("button_add_topic");
if(e != null) {
if(show_topics < max_topics)
button.disabled = false;
e.disabled = false;
else
button.disabled = true;
e.disabled = true;
}
button = document.getElementById("button_add_goal");
if(button != null) {
e = document.getElementById("button_add_goal");
if(e != null) {
if(show_goals < max_goals)
button.disabled = false;
e.disabled = false;
else
button.disabled = true;
e.disabled = true;
}
}
@@ -67,7 +68,6 @@
}
$(document).ready(function(){
console.log('document.ready()');
setupTopicsAndGoals();
});
</script>

View File

@@ -0,0 +1,27 @@
<script type="text/javascript">
var others_suffix = "_other";
function add_select_other_handler() {
var other_inputs = $("input[name$=" + others_suffix + "]");
var e;
for(var i = 0 ; i < other_inputs.length ; i++) {
(function(other_input) {
other_input.onkeyup = function() { select_other_handler(other_input.name); };
})(other_inputs[i]);
}
}
function select_other_handler(input_name) {
var input_element = $("#id_" + input_name);
if(input_element != null && input_element.val() != "") {
var select_name = input_name.substring(0, input_name.length - others_suffix.length);
var select_element = $("#id_" + select_name);
if(select_element != null)
select_element.val('OTHER');
}
}
$(document).ready(function(){
add_select_other_handler();
});
</script>