deform icon indicating copy to clipboard operation
deform copied to clipboard

AutocompleteInputWidget - more powerful configuration for typeahead.js

Open dairiki opened this issue 5 years ago • 1 comments

This is a redo of PR #185, rebased onto the current master branch.

dairiki avatar Jun 24 '20 18:06 dairiki

Some comments extracted/duplicated from PR #185

Problem: I had been relying on a hack to support JSON-esque serialization of values containing literal javascript using json.JSONEncoder from python’s standard library. It seems that my hack is not feasible in any version of python after 2.6 (). (My hack involved overriding JSONEncoder._iterencode, which does not exist in python >= 2.7.)

My hacked up version of JSONEncoder is JSONConfigSerializer in widget.py, which works with the new literal_js marker class which is defined just above it. The two unit tests which are currently failing are a result of these hacks not working in recent versions of python.

I see two ways forward:

  1. Implement our own serializer (more or less from scratch.)
  2. Find some other external JSON/javascript-serializer that will work for us. (I’m not sure that such a thing exists.) I’m not sure that either is worth the effort.

@stevepiercy responded:

Does this thread describe the same issue https://stackoverflow.com/a/53848267/2214933?

Does jsons do what is needed?

No, I think this is a different problem. At the root is the fact that we want to be able to serialize python data structures to javascript expressions which are not necessarily valid JSON. E.g. one would like to be able to include javascript function expressions, as well as function and variable names in the serialized result.

dairiki avatar Jun 24 '20 19:06 dairiki