kopia lustrzana https://github.com/wagtail/wagtail
Added hiddenfield
rodzic
9ac07d0a75
commit
32555f7a1c
|
@ -5,6 +5,7 @@ Changelog
|
|||
~~~~~~~~~~~~~~~~
|
||||
|
||||
* Removed support for Python 2.7, Django 1.8 and Django 1.10
|
||||
* Added hidden field to the form builder (Ross Crawford-d'Heureuse)
|
||||
* Fix: Do not remove stopwords when generating slugs from non-ASCII titles, to avoid issues with incorrect word boundaries (Sævar Öfjörð Magnússon)
|
||||
|
||||
|
||||
|
|
|
@ -257,6 +257,7 @@ Contributors
|
|||
* Mads Jensen
|
||||
* Samir Shah
|
||||
* Patrick Woods
|
||||
* Ross Crawford-d'Heureuse
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -13,6 +13,8 @@ What's new
|
|||
Other features
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
* Added hidden field to the form builder (Ross Crawford-d'Heureuse)
|
||||
|
||||
|
||||
Bug fixes
|
||||
~~~~~~~~~
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2017-10-13 16:10
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tests', '0020_customdocument'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='formfield',
|
||||
name='field_type',
|
||||
field=models.CharField(choices=[('singleline', 'Single line text'), ('multiline', 'Multi-line text'), ('email', 'Email'), ('number', 'Number'), ('url', 'URL'), ('checkbox', 'Checkbox'), ('checkboxes', 'Checkboxes'), ('dropdown', 'Drop down'), ('multiselect', 'Multiple select'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time'), ('hidden', 'Hidden field')], max_length=16, verbose_name='field type'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='formfieldwithcustomsubmission',
|
||||
name='field_type',
|
||||
field=models.CharField(choices=[('singleline', 'Single line text'), ('multiline', 'Multi-line text'), ('email', 'Email'), ('number', 'Number'), ('url', 'URL'), ('checkbox', 'Checkbox'), ('checkboxes', 'Checkboxes'), ('dropdown', 'Drop down'), ('multiselect', 'Multiple select'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time'), ('hidden', 'Hidden field')], max_length=16, verbose_name='field type'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='jadeformfield',
|
||||
name='field_type',
|
||||
field=models.CharField(choices=[('singleline', 'Single line text'), ('multiline', 'Multi-line text'), ('email', 'Email'), ('number', 'Number'), ('url', 'URL'), ('checkbox', 'Checkbox'), ('checkboxes', 'Checkboxes'), ('dropdown', 'Drop down'), ('multiselect', 'Multiple select'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time'), ('hidden', 'Hidden field')], max_length=16, verbose_name='field type'),
|
||||
),
|
||||
]
|
|
@ -76,6 +76,9 @@ class FormBuilder(object):
|
|||
def create_checkbox_field(self, field, options):
|
||||
return django.forms.BooleanField(**options)
|
||||
|
||||
def create_hidden_field(self, field, options):
|
||||
return django.forms.CharField(widget=django.forms.HiddenInput, **options)
|
||||
|
||||
FIELD_TYPES = {
|
||||
'singleline': create_singleline_field,
|
||||
'multiline': create_multiline_field,
|
||||
|
@ -89,6 +92,7 @@ class FormBuilder(object):
|
|||
'radio': create_radio_field,
|
||||
'checkboxes': create_checkboxes_field,
|
||||
'checkbox': create_checkbox_field,
|
||||
'hidden': create_hidden_field,
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
|
@ -33,6 +33,7 @@ FORM_FIELD_CHOICES = (
|
|||
('radio', _('Radio buttons')),
|
||||
('date', _('Date')),
|
||||
('datetime', _('Date/time')),
|
||||
('hidden', _('Hidden field')),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -111,6 +111,13 @@ class TestFormBuilder(TestCase):
|
|||
field_type='checkbox',
|
||||
required=True,
|
||||
)
|
||||
FormField.objects.create(
|
||||
page=self.form_page,
|
||||
sort_order=1,
|
||||
label="A Hidden Field",
|
||||
field_type='hidden',
|
||||
required=False,
|
||||
)
|
||||
|
||||
# Create a form builder
|
||||
self.fb = FormBuilder(self.form_page.get_form_fields())
|
||||
|
@ -135,6 +142,7 @@ class TestFormBuilder(TestCase):
|
|||
self.assertIn('your-favourite-python-ide', field_names)
|
||||
self.assertIn('your-choices', field_names)
|
||||
self.assertIn('i-agree-to-the-terms-of-use', field_names)
|
||||
self.assertIn('a-hidden-field', field_names)
|
||||
|
||||
# All fields have proper type
|
||||
self.assertIsInstance(form_class.base_fields['your-name'], forms.CharField)
|
||||
|
@ -149,8 +157,10 @@ class TestFormBuilder(TestCase):
|
|||
self.assertIsInstance(form_class.base_fields['your-favourite-python-ide'], forms.ChoiceField)
|
||||
self.assertIsInstance(form_class.base_fields['your-choices'], forms.MultipleChoiceField)
|
||||
self.assertIsInstance(form_class.base_fields['i-agree-to-the-terms-of-use'], forms.BooleanField)
|
||||
self.assertIsInstance(form_class.base_fields['a-hidden-field'], forms.CharField)
|
||||
|
||||
# Some fields have non-default widgets
|
||||
self.assertIsInstance(form_class.base_fields['your-message'].widget, forms.Textarea)
|
||||
self.assertIsInstance(form_class.base_fields['your-favourite-python-ide'].widget, forms.RadioSelect)
|
||||
self.assertIsInstance(form_class.base_fields['your-choices'].widget, forms.CheckboxSelectMultiple)
|
||||
self.assertIsInstance(form_class.base_fields['a-hidden-field'].widget, forms.HiddenInput)
|
||||
|
|
Ładowanie…
Reference in New Issue