mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Introduce ArrayWidget for more convenient editing of choices
This commit is contained in:
parent
00096ccb2b
commit
ed2d78fef4
@ -19,6 +19,7 @@ from utilities.forms.fields import (
|
||||
CommentField, ContentTypeChoiceField, ContentTypeMultipleChoiceField, DynamicModelChoiceField,
|
||||
DynamicModelMultipleChoiceField, JSONField, SlugField,
|
||||
)
|
||||
from utilities.forms.widgets import ArrayWidget
|
||||
from virtualization.models import Cluster, ClusterGroup, ClusterType
|
||||
|
||||
|
||||
@ -84,11 +85,18 @@ class CustomFieldForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class CustomFieldChoiceSetForm(BootstrapMixin, forms.ModelForm):
|
||||
extra_choices = forms.CharField(
|
||||
widget=ArrayWidget(),
|
||||
help_text=_('Enter one choice per line.')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = CustomFieldChoiceSet
|
||||
fields = ('name', 'description', 'extra_choices', 'order_alphabetically')
|
||||
|
||||
def clean_extra_choices(self):
|
||||
return self.cleaned_data['extra_choices'].split('\n')
|
||||
|
||||
|
||||
class CustomLinkForm(BootstrapMixin, forms.ModelForm):
|
||||
content_types = ContentTypeMultipleChoiceField(
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django import forms
|
||||
|
||||
__all__ = (
|
||||
'ArrayWidget',
|
||||
'ClearableFileInput',
|
||||
'MarkdownWidget',
|
||||
'NumberWithOptions',
|
||||
@ -43,3 +44,13 @@ class SlugWidget(forms.TextInput):
|
||||
Subclass TextInput and add a slug regeneration button next to the form field.
|
||||
"""
|
||||
template_name = 'widgets/sluginput.html'
|
||||
|
||||
|
||||
class ArrayWidget(forms.Textarea):
|
||||
"""
|
||||
Render each item of an array on a new line within a textarea for easy editing/
|
||||
"""
|
||||
def format_value(self, value):
|
||||
if value is None or not len(value):
|
||||
return None
|
||||
return '\n'.join(value)
|
||||
|
Loading…
Reference in New Issue
Block a user