django-jsonform
django-jsonform copied to clipboard
Choice field returning empty values
Hi @bhch
I have a form displaying the following address information. The state choices is filled based on country through jQuery. The problem is, the address object in DB is empty i.e. {country:"",state:""}.
Am i missing something?
django version: 3.2 using jazzmin for the dashboard UI
ADDRESS={ "type": "dict", "keys": { "country": { "type": "string", 'choices': ['India','China',....] }, "state": { "type": "string", 'choices': [] } } }
//models.js address = JSONField(schema=ADDRESS)
Are you populating the state
input field using JQuery?
Yes! But I tried with static values in state too. It is still same as using jQuery
The actual JSON data is kept in a hidden textarea. So modifying the input field with jQuery will not change the data.
But it's strange that it's not working with predefined values either. Could you tell me which version you're using?
Check it with this command:
$ python -c "import django_jsonform; print(django_jsonform.__version__)"
version: 2.10.1 At least the country field is predefined. So am expecting a value for that.
If it is a normal schema with array of objects or so, I can see the data in clean method (populated through jQuery)
I tried the schema you gave me but I'm unable to reproduce this issue. It's working fine for me.
If you could create a sample repository with some code to reproduce this, it'll be quicker for me to just clone and test it out.
@kayesn786 Do you still have this issue?
Currently, I'm working on a new version. I've been thinking about providing some JavaScript apis to control the form in the browser, such as events handlers and functions etc. Those will be useful in cases like this issue.
If you have any ideas, I'd appreciate your input.
@bhch the issue was with adding dynamic options with jQuery. Django was not recognizing those dynamically added
However, I would love to have a feature that selects a schema based on some other field in the form.
Hi, I've added a basic JavaScript API (see docs) which will allow you to dynamically update the schema and the widget.
Please upgrade to v2.11.0 and test it out.
In future, I'll add support for if-then-else
keywords in the schema.