Hide and show the count input as required
This commit is contained in:
@ -6,6 +6,7 @@ from django.conf import settings
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.models import AnonymousUser
|
from django.contrib.auth.models import AnonymousUser
|
||||||
from django.contrib.sessions.models import Session
|
from django.contrib.sessions.models import Session
|
||||||
|
from django.contrib.staticfiles.templatetags.staticfiles import static
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
@ -67,3 +68,11 @@ class SegmentAdminForm(WagtailAdminModelForm):
|
|||||||
instance.sessions.add(session)
|
instance.sessions.add(session)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
@property
|
||||||
|
def media(self):
|
||||||
|
media = super(SegmentAdminForm, self).media
|
||||||
|
media.add_js(
|
||||||
|
[static('js/segment_form_control.js')]
|
||||||
|
)
|
||||||
|
return media
|
||||||
|
@ -98,7 +98,7 @@ class Segment(ClusterableModel):
|
|||||||
]),
|
]),
|
||||||
FieldPanel('match_any'),
|
FieldPanel('match_any'),
|
||||||
FieldPanel('type', widget=forms.RadioSelect),
|
FieldPanel('type', widget=forms.RadioSelect),
|
||||||
FieldPanel('count'),
|
FieldPanel('count', classname='count_field'),
|
||||||
], heading="Segment"),
|
], heading="Segment"),
|
||||||
MultiFieldPanel([
|
MultiFieldPanel([
|
||||||
InlinePanel(
|
InlinePanel(
|
||||||
|
@ -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);
|
Reference in New Issue
Block a user