viewflow.forms.InlineCalendar(attrs=None, format=None)¶InlineCalendar: A full-sized month calendar widget for Django forms.
See the demo at: https://demo.viewflow.io/widget/inlinecalendar/
Usage:
from viewflow.forms import InlineCalendar
class InlineCalendarForm(forms.Form):
    start_date = forms.DateField(
        help_text="custom input format",
        initial=date(1969, 7, 21),
        input_formats=["%d.%m.%Y"],
        widget=InlineCalendar(format="%d.%m.%Y"),
    )
viewflow.forms.AjaxModelSelect(*args, **kwargs)¶A widget for ModelChoiceField providing AJAX-based autocomplete functionality.
See the demo at: https://demo.viewflow.io/atlas/city/add/
Demo source code CRUD101::Atlas
To integrate AjaxModelSelect in a Django form:
from viewflow.forms import InlineCalendar
class AddressForm(ModelForm):
    class Meta:
        model = models.Address
        fields = '__all__'
        widgets = {
            'country': AjaxModelSelect(lookups=['name__istartswith'])
        }
To fetch suggestions, an OPTIONS request is made to the form’s URL with an additional X-Request-Autocomplete HTTP header.
if request.method == "OPTIONS" and "HTTP_X_REQUEST_AUTOCOMPLETE" in request.META:
    query = request.META.get("HTTP_X_REQUEST_AUTOCOMPLETE")
    options = QueryDict(query, encoding=self.request.encoding)
    field_name = options.get("field", "")
    query = options.get("query")
    ...
The server should return a JSON response structured as:
{
    "suggestions": [
        { "value": "Chicago Blackhawks", "data": { "id": 1 } },
        { "value": "Chicago Bulls", "data": { "id": 2 } }
    ]
}
To simplify the integration, use the built-in FormAjaxCompleteMixin:
from viewflow.forms import FormAjaxCompleteMixin
class UpdateAddressView(FormAjaxCompleteMixin, generic.UpdateView):
    form_class = AddressForm
viewflow.forms.AjaxMultipleModelSelect(*args, **kwargs)¶A widget designed for ModelMultipleChoiceField that introduces AJAX-based autocomplete functionality for multiple selections.
This widget is suitable for forms where users might need to select multiple entries from a model, with the convenience of autocomplete suggestions as they type.
The behavior of this widget is similar to AjaxModelSelect, but is tailored for handling multiple model choices.
To integrate AjaxModelSelect in a Django form:
class CountryForm(forms.Form):
    cities = forms.ModelMultipleChoiceField(
        queryset=City.objects.all(),
        widget=widgets.AjaxMultipleModelSelect(lookups=["name__istartswith"]),
        help_text="default",
    )
Demo source code CRUD101::Atlas
viewflow.form.widgets.AjaxModelSelect.viewflow.forms.TrixEditorWidget(options=None, *args, **kwargs)¶WYSIWYG editor widget based on the Trix editor.
See a demo: https://demo.viewflow.io/review/review/add/
from viewflow.forms import TrixEditorWidget
from viewflow.views import CreateModelView
class AddReviewView(CreateModelView):
    fields = ["title", "text"]
    form_widgets = {"text": TrixEditorWidget}
See also
viewflow.forms.DependentModelSelect(*args, **kwargs)¶A chained select widget where choice options depend on the value selected in another field.
For a model named Sea with a field parent see that depends on the ocean field:
class SeaViewset(DeleteViewMixin, ModelViewset):
    model = models.Sea
    form_widgets = {
        'parent': DependentModelSelect(
            depends_on='ocean', queryset=lambda parent:
            models.Sea.objects.filter(ocean=parent)
        )
    }
Demo source code CRUD101::Atlas
Choices are fetched via an OPTIONS request to the form’s URL with the additional X-Request-Select-Options HTTP header.
if request.method == "OPTIONS" and "HTTP_X_REQUEST_SELECT_OPTIONS" in request.META:
    query = request.META.get("HTTP_X_REQUEST_SELECT_OPTIONS")
    options = QueryDict(query, encoding=self.request.encoding)
    field_name = options.get("field", "")
    query = options.get("query")
    ...
The server should return a JSON response structured as:
{
    "data":  [
        {'name': "", "options": {"key1": "value1", "key2": "value2", ...}}
        {'name': "Option group", "options": {"key3": "value3", "key4": "value4", ...}}
    ]
}
To simplify the integration, use the built-in FormDependentSelectMixin
from viewflow.forms import FormDependentSelectMixin
class SeeView(FormDependentSelectMixin, generic.UpdateView):
    ...
viewflow.forms.TotalCounterWidget(*args, expression='', round=None, **kwargs)¶A widget to calculate the total for form fields based on given expressions.
See a demo: https://demo.viewflow.io/workflow/flows/shipment/start/
Demo source code Workflow101::Shipment
Usage:
from viewflow.forms import TotalCounterWidget class ShipmentForm(ModelForm): items = InlineFormSetField( Shipment, ShipmentItem, fields=["name", "quantity", "cost"], can_delete=False, extra=1, ) total = forms.CharField( widget=TotalCounterWidget(expression="sum(items.quantity*items.cost)"), label="", ) layout = Layout( "items", Row( Tag( "h4", text="Total:", style="text-align:right", class_="mdc-typography", ), "total", ), )
viewflow.forms.JSONEditorWiget(attrs=None)¶