re: Django inline formsets with Class-based views and crispy forms VIEW POST

re: Hey thanks a ton for this tutorial, im still quite new to django so I was wondering how would I go about adding a validation so at least one Collec...

So I've figured out how to add validation for the CollectionTitle, but im doing it through Wondering if anybody knows how to add the validation to client side instead of going through views, thanks.

How I am doing it at the moment is adding a min_num and validate_min to the inlineformset_factory.

CollectionTitleFormSet = inlineformset_factory(
    Collection, CollectionTitle, form=CollectionTitleForm,
    fields=['name', 'language'], can_delete=True, min_num=1, validate_min=True, extra=0

And by setting an else function in the form_valid. I save the object after validating titles since my project requires at least one title for each collection.

class CollectionCreate(CreateView):
#kept rest the same till form_valid

def form_valid(self, form):
        context = self.get_context_data()
        titles = context['titles']
        with transaction.atomic():
            form.instance.created_by = self.request.user
            if titles.is_valid():
                self.object =
                titles.instance = self.object
                context.update({'titles': titles})
                return self.render_to_response(context)
        return super(CollectionCreate, self).form_valid(form)
code of conduct - report abuse