Opened 20 months ago

Last modified 20 months ago

#34329 closed Bug

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 — at Version 2

Reported by: Sasikumar K Owned by: nobody
Component: Forms Version: 4.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Sasikumar K)

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='placenameicontains',
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 %}

Change History (3)

by Sasikumar K, 20 months ago

Attachment: error1.png added

comment:1 by Sasikumar K, 20 months ago

Description: modified (diff)
Needs documentation: set

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='placenameicontains',
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:2 by Sasikumar K, 20 months ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top