Giter Site home page Giter Site logo

Comments (2)

zodman avatar zodman commented on June 27, 2024

i can reproduce with this:


diff --git a/widget_tweaks/tests.py b/widget_tweaks/tests.py
index ee210a2..a944afe 100644
--- a/widget_tweaks/tests.py
+++ b/widget_tweaks/tests.py
@@ -7,7 +7,7 @@ except ImportError:
 
 from django import VERSION
 from django import forms
-from django.forms import Form, CharField, TextInput
+from django.forms import Form, CharField, TextInput, SplitDateTimeField, SplitDateTimeWidget
 from django.template import Template, Context
 
 try:
@@ -15,6 +15,14 @@ try:
 except ImportError:
     from django.forms.extras.widgets import SelectDateWidget  # django < 2.0
 
+if VERSION[0] == 2:
+    date_time_params = dict(
+        time_attrs={'class': 'datepicker'}, date_attrs={'class': 'timepicker'}
+    )
+else:
+    date_time_params = {}
+
+
 
 # ==============================
 #       Testing helpers
@@ -33,6 +41,7 @@ class MyForm(Form):
     }))
     with_cls = CharField(widget=TextInput(attrs={'class': 'class0'}))
     date = forms.DateField(widget=SelectDateWidget(attrs={'egg': 'spam'}))
+    date_time = forms.SplitDateTimeField(widget=SplitDateTimeWidget(**date_time_params))
 
 
 def render_form(text, form=None, **context_args):
@@ -119,6 +128,12 @@ class SimpleAttrTest(TestCase):
         res = render_field('simple', 'set_data', 'key:value')
         assertIn('data-key="value"', res)
 
+    def test_widget_split(self):
+        if VERSION[0]  == 2:
+            res = render_field('date_time', 'add_class', 'validate')
+            assertIn("datepicker", res)
+            assertIn("timepicker", res)
+
 
 class ErrorsTest(TestCase):
 
@@ -314,6 +329,13 @@ class RenderFieldTagFieldReuseTest(TestCase):
         res = render_form('{{ form.simple }}{% render_field form.simple foo="bar" %}{% render_field form.simple %}')
         self.assertEqual(res.count("bar"), 1)
 
+    
+    def test_field_datetime_widget(self): #  issue #66 from github
+        if VERSION[0] == 2:
+            res = render_form('{{ form.simple }}{% render_field form.date_time class+="validate" %}')
+            self.assertEqual(res.count("timepicker"), 1, res)
+            self.assertEqual(res.count("datepicker"), 1, res)
+
     def test_field_double_rendering_simple_css(self):
         res = render_form('{% render_field form.simple %}{% render_field form.simple class+="bar" %}{% render_field form.simple class+="baz" %}')
         self.assertEqual(res.count("baz"), 1)

the pass show it clear:

test_field_datetime_widget (widget_tweaks.tests.RenderFieldTagFieldReuseTest) ... FAIL

======================================================================
FAIL: test_field_datetime_widget (widget_tweaks.tests.RenderFieldTagFieldReuseTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/zodman/apps/django-widget-tweaks/widget_tweaks/tests.py", line 336, in test_field_datetime_widget
    self.assertEqual(res.count("timepicker"), 1, res)
AssertionError: 0 != 1 : <input type="text" name="simple" required id="id_simple" /><input type="text" name="date_time_0" class="validate" required id="id_date_time_0" /><input type="text" name="date_time_1" class="validate" required id="id_date_time_1" />

from django-widget-tweaks.

zodman avatar zodman commented on June 27, 2024

SplitDateTimeField its a MultiWidget and not supported!

from django-widget-tweaks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.