7

Hide and show the count input as required

This commit is contained in:
Todd Dembrey
2017-10-26 11:47:28 +01:00
parent 7cf22d05f6
commit bc0b69fde5
3 changed files with 28 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.contrib.sessions.models import Session
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.core.exceptions import ValidationError
from django.test.client import RequestFactory
from django.utils import timezone
@ -67,3 +68,11 @@ class SegmentAdminForm(WagtailAdminModelForm):
instance.sessions.add(session)
return instance
@property
def media(self):
media = super(SegmentAdminForm, self).media
media.add_js(
[static('js/segment_form_control.js')]
)
return media

View File

@ -98,7 +98,7 @@ class Segment(ClusterableModel):
]),
FieldPanel('match_any'),
FieldPanel('type', widget=forms.RadioSelect),
FieldPanel('count'),
FieldPanel('count', classname='count_field'),
], heading="Segment"),
MultiFieldPanel([
InlinePanel(

View File

@ -0,0 +1,18 @@
(function($) {
$(document).ready( () => {
var count = $('.count_field');
count.hide();
var updateCountDispay = function(value) {
if (value == 'dynamic') {
count.slideUp(250);
} else {
count.slideDown(250);
}
};
$('input:radio[name="type"]').change( event => {
updateCountDispay(event.target.value);
});
});
})(jQuery);