#14978 closed enhancement (worksforme)
Dojo parser: parsing comma-separated elements into an array should support a way to escape commas inside elements
Reported by: | Adrian Vasiliu | Owned by: | bill |
---|---|---|---|
Priority: | undecided | Milestone: | tbd |
Component: | Parser | Version: | 1.7.2 |
Keywords: | Cc: | cjolif | |
Blocked By: | Blocking: |
Description (last modified by )
Various widgets have properties of type Array that can be specified in mark-up using strings. For example, one can specify
<div data-dojo-type="dojox.mobile.SpinWheelSlot?"
labels="'a','b'" ...>
or <div data-dojo-type="dojox.mobile.SpinWheelSlot?"
labels="a,b" ...>
The Dojo parser transforms these comma-separated strings into an array of 2 elements (this holds for both dojo/parser and dojox/mobile/parser).
So far so good, but it seems there's currently no easy way to include a comma in an element. Say, if we need an array of 2 elements, "a,A" and "b,B", specifying
<div data-dojo-type="dojox.mobile.SpinWheelSlot?"
labels="'a,A','b,B'" ...>
the parsed array contains 4, not 2 elements.
The following attempts to escape the comma character do not work either:
<div data-dojo-type="dojox.mobile.SpinWheelSlot?"
labels="'a\,A','b\,B'" ...>
<div data-dojo-type="dojox.mobile.SpinWheelSlot?"
labels="'a,A','b,B'" ...>
How to reproduce:
- Unzip the attached testParser.zip, say into the parent folder of dojo and dijit (otherwise, adapt the paths in test.html). This contains test.html which includes in mark-up three occurrences of a dijit widget defined in TestWidget?.js, using different ways to define an array of 2 elements each containing a comma.
- Run test/test.html
=> The console shows the elements of the parsed arrays. In all cases, the array has 4, not 2 elements.
Attachments (1)
Change History (5)
Changed 9 years ago by
comment:1 Changed 9 years ago by
Cc: | cjolif added |
---|---|
Component: | General → Parser |
Owner: | set to bill |
comment:2 Changed 9 years ago by
Description: | modified (diff) |
---|
comment:3 Changed 9 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
This already works via the data-dojo-props syntax:
data-dojo-props='labels: ["A, a", "B, b"]'
Let us know if there's something else you need.
I don't see a reason to have this functionality on direct widget attributes (ie, attributes like label in your example above) since our trend is to only use direct attributes where there are corresponding native DOMNode attributes (as defined in the HTML spec).
comment:4 Changed 9 years ago by
Yes, using data-dojo-props it works fine indeed. Thanks for the hint.
Sample for reproducing.