Closed sasikumar1978k closed 1 year ago
seems that you're interpreting HTML as JSON.
A bug report like this, without any context is quite useless for me.
I'm facing the same issue.
version: 1.0.1
# models
class Donor(models.Model):
name = models.CharField(max_length=32)
class FundAccount(models.Model):
donor = models.ForeignKey(Donor)
name = models.CharField(max_length=32)
class Scholarship(models.Model):
fund_account = models.ForeignKey(FundAccount)
name = models.CharField(max_length=32)
# forms.py
class ScholarshipForm(forms.ModelForm):
donor = forms.ModelChoiceField(
queryset=Donor.objects.all(),
)
fund_account = forms.ModelChoiceField(
queryset=FundAccount.objects.all(),
widget=Selectize(
filter_by={'donor':'donor__id'},
)
)
class Meta:
model = Scholarship
fields = ['name']
Error when placing input in donor field in form will cause this issue:
Seems that the js script is reading the whole html document rather than it's capturing json data
Note that this only occurs if I use the filter_by parameter in selectize. If I do not use filter_by, I don't get the issue
Why didn't you use widget Selectize
for field donor?
Anyway, that doesn't seem to be the problem, I just tested with the example https://github.com/jrief/django-formset/blob/main/testapp/forms/state.py and everything works fine for me.
I didn't use Selectize
for donor field to isolate the problem that uses filter_by. Lol
I found the issue here to be from my source code
If ever someone would encounter this problem, please ensure that the view you are inheriting also inherits IncompleteSelectResponseMixin
in formset.views
since in my sourcecode I did this implementation:
from formset.views import FormViewMixin
from .forms import ScholarshipForm
class ScholarshipCreateView(..., FormViewMixin, CreateView):
form_class = ScholarshipForm
It was not able to properly process the form using the IncompleteSelectResponseMixin
.
A question for @jrief, is it possible for FormViewMixin
to inherit IncompleteSelectResponseMixin
by default? This could potentially avoid the same case for other developers. I'm just not sure if there will be conflicts or implications for doing so.
Thanks you still for your assistance! Will continue to support your library and try to report or debug any vulnerabilities as I hope for further development of this library :)
A question for @jrief, is it possible for FormViewMixin to inherit IncompleteSelectResponseMixin by default? This could potentially avoid the same case for other developers. I'm just not sure if there will be conflicts or implications for doing so.
IncompleteSelectResponseMixin
is only required, if you're using the Selectize
and DualSelector
widget with asynchronous loading. Not everyone needs that and therefore I prefer to not add another moving part.
i am facing the following error in my modelchoice control change event
Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
MY CODE
my model class Places(models.Model): placename = models.CharField(max_length=50,unique=True) blockname = models.CharField(max_length=50) pincode = models.CharField(max_length=6) TALUKNAME = models.CharField(max_length=50) rev_dist = models.ForeignKey(REVDISTDET, on_delete=models.CASCADE, verbose_name='REVENUE DISTRICT',default='',null=True, ) edn_dist = models.ForeignKey(EDNDISTDET, on_delete=models.CASCADE, verbose_name='REVENUE DISTRICT',default='',null=True, )
class Officedet(models.Model):
my form class OfficedetForm(forms.ModelForm):
"office_name", "office_mail", "office_place", "office_gender_type", "office_mgnt_type", "office_class_level", "office_type", 'office_tanno', 'office_udisecode', "office_logo", ]
My view class OfficeDetailCreateView(AdminUserTypeAuthMixin,FileUploadMixin, FormViewMixin, LoginRequiredMixin, CreateView): model = Officedet template_name = 'home/crud/crud_template.html' form_class = OfficedetForm success_url = reverse_lazy('office_list_view') # or whatever makes sense extra_context = { 'pagetitle':'Office Creation' } my template {% extends "layouts/masterpage-formset.html" %} {% block pagecontent %} {% load render_form from formsetify %}
{% endblock pagecontent %}