Re: [Django] #34329: django-formset new app - i am facing the issue Uncaught (in promise) SyntaxError: JSON.parse (was: django-formset new app - i am facing the issue Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data)

2 views
Skip to first unread message

Django

unread,
Feb 10, 2023, 2:21:47 AM2/10/23
to django-...@googlegroups.com
#34329: django-formset new app - i am facing the issue Uncaught (in promise)
SyntaxError: JSON.parse
-----------------------------+--------------------------------------
Reporter: Sasikumar K | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 4.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* needs_docs: 1 => 0
* resolution: => invalid


Old description:

> I am new to django . while i am trying to use django-formset third party
> app in my form modelchoice control change event show the error -
> Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at
> line 1 column 1 of the JSON data - i have spent 6 hours i could not fix
> the error.
>

>

> form.py
>
> class OfficedetForm(forms.ModelForm):
>
> office_logo = fields.FileField(
> label="Office Logo",
> widget=UploadedFileInput,
> required=True,
> )
>
> office_gender_type = forms.ModelChoiceField(
> queryset=OFFICE_GENDER_TYPE_CHOICE.objects.all(),
> widget=Selectize(
>
> placeholder="Choose Gender",
> ),
> )
>
> office_mgnt_type = forms.ModelChoiceField(
> queryset=OFFICE_MGNT_TYPE_CHOICE.objects.all(),
> widget=Selectize(
>
> placeholder="Choose Management",
> ),
> )
>
> office_class_level = forms.ModelChoiceField(
> queryset=OfficeClassLevel.objects.all(),
> widget=Selectize(
>
> placeholder="Choose Class Level",
> ),
> )
>
> office_place = forms.ModelChoiceField(
> queryset=Places.objects.all(),
> widget=Selectize(
> search_lookup='placename__icontains',
> placeholder="Choose Place",
>
> ),
> )
>
> office_type = forms.ChoiceField(
> choices=[ ('SCHOOL','SCHOOL'),
> ('ADMIN','ADMIN'),],
> widget=Selectize,
> )
>

> default_renderer = FormRenderer(
> form_css_classes='row',
> field_css_classes={
> '*': 'mb-2 col-12',
> "office_code": 'mb-2 col-2',
> "office_name": 'mb-2 col-4',
> "office_mail": 'mb-2 col-3',
> "office_place": 'mb-2 col-3',
> '*': 'mb-2 col-12',
> "office_gender_type": 'mb-2 col-3',
> "office_mgnt_type": 'mb-2 col-3',
> "office_class_level": 'mb-2 col-3',
> "office_type": 'mb-2 col-3',
>
> '*': 'mb-2 col-12',
> "office_tanno": 'mb-2 col-4',
> "office_udisecode": 'mb-2 col-4',
> "office_logo": 'mb-2 col-4',
>

> }
> )
> class Meta:
> model = Officedet
> fields = ["office_code",
> "office_name",
> "office_mail",
> "office_place",
> "office_gender_type",
> "office_mgnt_type",
> "office_class_level",
> "office_type",
> 'office_tanno',
> 'office_udisecode',
> "office_logo",
> ]
>

> views.py
>

> 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'
> }
>
> page.html
>
> {% extends "layouts/masterpage-formset.html" %}
> {% block pagecontent %}
> {% load render_form from formsetify %}
> <django-formset endpoint="{{ request.path }}" csrf-token="{{ csrf_token
> }}">
> {% render_form form %}
>

> <div class="{{ button_css_classes }}">
> <button type="button" click="disable -> confirm('Do want to Submit
> ?') -> spinner -> submit -> okay(500) -> proceed" auto-disable="{{
> auto_disable|yesno:'true,false' }}" class="btn btn-primary">Submit<span
> class="ms-2 dj-button-decorator"><i class="bi bi-
> send"></i></span></button>
> <button type="button" click="reset" class="ms-2 btn btn-
> warning">Reset</button>
> <button click="proceed('/office_list_view/')" class="btn btn-
> info">Back to list</button>
>
> </div>
> </django-formset>
> {% endblock pagecontent %}

New description:

I am new to django . while i am trying to use django-formset third party
app in my form modelchoice control change event show the error -
Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at
line 1 column 1 of the JSON data - i have spent 6 hours i could not fix
the error.

{{{
form.py

class OfficedetForm(forms.ModelForm):

office_logo = fields.FileField(
label="Office Logo",
widget=UploadedFileInput,
required=True,
)

office_gender_type = forms.ModelChoiceField(
queryset=OFFICE_GENDER_TYPE_CHOICE.objects.all(),
widget=Selectize(

placeholder="Choose Gender",
),
)

office_mgnt_type = forms.ModelChoiceField(
queryset=OFFICE_MGNT_TYPE_CHOICE.objects.all(),
widget=Selectize(

placeholder="Choose Management",
),
)

office_class_level = forms.ModelChoiceField(
queryset=OfficeClassLevel.objects.all(),
widget=Selectize(

placeholder="Choose Class Level",
),
)

office_place = forms.ModelChoiceField(
queryset=Places.objects.all(),
widget=Selectize(
search_lookup='placename__icontains',
placeholder="Choose Place",

),
)

office_type = forms.ChoiceField(
choices=[ ('SCHOOL','SCHOOL'),
('ADMIN','ADMIN'),],
widget=Selectize,
)


default_renderer = FormRenderer(
form_css_classes='row',
field_css_classes={
'*': 'mb-2 col-12',
"office_code": 'mb-2 col-2',
"office_name": 'mb-2 col-4',
"office_mail": 'mb-2 col-3',
"office_place": 'mb-2 col-3',
'*': 'mb-2 col-12',
"office_gender_type": 'mb-2 col-3',
"office_mgnt_type": 'mb-2 col-3',
"office_class_level": 'mb-2 col-3',
"office_type": 'mb-2 col-3',

'*': 'mb-2 col-12',
"office_tanno": 'mb-2 col-4',
"office_udisecode": 'mb-2 col-4',
"office_logo": 'mb-2 col-4',


}
)
class Meta:
model = Officedet
fields = ["office_code",
"office_name",
"office_mail",
"office_place",
"office_gender_type",
"office_mgnt_type",
"office_class_level",
"office_type",
'office_tanno',
'office_udisecode',
"office_logo",
]


views.py


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'
}

page.html

{% extends "layouts/masterpage-formset.html" %}
{% block pagecontent %}
{% load render_form from formsetify %}
<django-formset endpoint="{{ request.path }}" csrf-token="{{ csrf_token
}}">
{% render_form form %}


<div class="{{ button_css_classes }}">
<button type="button" click="disable -> confirm('Do want to Submit ?')
-> spinner -> submit -> okay(500) -> proceed" auto-disable="{{
auto_disable|yesno:'true,false' }}" class="btn btn-primary">Submit<span
class="ms-2 dj-button-decorator"><i class="bi bi-
send"></i></span></button>
<button type="button" click="reset" class="ms-2 btn btn-
warning">Reset</button>
<button click="proceed('/office_list_view/')" class="btn btn-
info">Back to list</button>

</div>
</django-formset>
{% endblock pagecontent %}
}}}

--

Comment:

Please don't use Trac as a support channel. Closing per
TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/34329#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages