Permalink
Browse files

Fine-tuned fix of errormarkerclass for nested arrays (#67 and #102)

Many thanks for the pull request, @flisky. The line you fixed was
indeed the line that caused problem. However, while the "g" flag is
indeed needed to support nested arrays, that was not enough to
produce the right output.

Typically, the goal is to generate something like "map[0][0].index"
from:
 "urn:uuid:a6d3a998-fb94-4acd-9986-d6d6a23e8eb3#/map/0/0/index"

The first two regular expressions turn the input into:
 "map.0.0.index"

Just adding the "g" flag to the final regular expression woud not
really change anything in most cases, leading to:
 "map[0].0.index"

The following "." should not have been part of the match, I added the
right lookahead pattern. That seems to work fine in the forms I tried.
  • Loading branch information...
1 parent 4004f14 commit 43f0e6c4f0835e0705831d48dee7355fbaa95867 François Daoust committed Jan 3, 2014
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/jsonform.js
View
@@ -3464,7 +3464,7 @@ $.fn.jsonFormErrors = function(errors, options) {
var key = errors[i].uri
.replace(/.*#\//, '')
.replace(/\//g, '.')
- .replace(/\.([0-9]+)(\.|$)/g, '[$1]$2');
+ .replace(/\.([0-9]+)(?=\.|$)/g, '[$1]');
var errormarkerclass = ".jsonform-error-" +
escapeSelector(key.replace(/\./g,"---"));
errorSelectors.push(errormarkerclass);

0 comments on commit 43f0e6c

Please sign in to comment.