Use safer field ids in classes, element ids, css selectors

Fixes issue with nested/namespaced fields, such as `maxspeed/advisory`,
in situations where would try to use a css selector or element id.
Can't use characters like '/' in a css selector.
This commit is contained in:
Bryan Housel
2018-03-15 00:57:41 -04:00
parent b6b6232532
commit 4a71aa6146
14 changed files with 30 additions and 14 deletions
+5
View File
@@ -827,6 +827,11 @@ en:
label: Speed Limit
# maxspeed field placeholder
placeholder: '40, 50, 60...'
maxspeed/advisory:
# 'maxspeed:advisory=*'
label: Advisory Speed Limit
# maxspeed/advisory field placeholder
placeholder: '40, 50, 60...'
maxstay:
# maxstay=*
label: Max Stay
+2 -2
View File
@@ -1139,7 +1139,7 @@
"label": "Speed Limit",
"placeholder": "40, 50, 60..."
},
"maxspeed/advisory":{
"maxspeed/advisory": {
"key": "maxspeed:advisory",
"type": "maxspeed",
"label": "Advisory Speed Limit",
@@ -2257,4 +2257,4 @@
}
}
}
}
}
+5
View File
@@ -7290,6 +7290,7 @@
"ref_road_number",
"oneway",
"maxspeed",
"maxspeed/advisory",
"lanes",
"surface",
"structure",
@@ -7440,6 +7441,7 @@
"name",
"oneway",
"maxspeed",
"maxspeed/advisory",
"lanes",
"surface",
"maxheight",
@@ -7586,6 +7588,7 @@
"name",
"oneway",
"maxspeed",
"maxspeed/advisory",
"lanes",
"surface",
"structure",
@@ -7878,6 +7881,7 @@
"name",
"oneway",
"maxspeed",
"maxspeed/advisory",
"lanes",
"surface",
"structure",
@@ -8017,6 +8021,7 @@
"ref_road_number",
"oneway",
"maxspeed",
"maxspeed/advisory",
"lanes",
"surface",
"structure",
+4
View File
@@ -2064,6 +2064,10 @@
"label": "Speed Limit",
"placeholder": "40, 50, 60..."
},
"maxspeed/advisory": {
"label": "Advisory Speed Limit",
"placeholder": "40, 50, 60..."
},
"maxstay": {
"label": "Max Stay"
},
+2
View File
@@ -7,6 +7,8 @@ export function presetField(id, field) {
field.id = id;
// for use in classes, element ids, css selectors
field.safeid = id.replace(/[^_a-zA-Z0-9\-]/g, '_');
field.matchGeometry = function(geometry) {
return !field.geometry || field.geometry === geometry;
+2 -2
View File
@@ -96,14 +96,14 @@ export function uiField(context, presetField, entity, options) {
// Enter
var enter = container.enter()
.append('div')
.attr('class', function(d) { return 'form-field form-field-' + d.id; })
.attr('class', function(d) { return 'form-field form-field-' + d.safeid; })
.classed('nowrap', !options.wrap);
if (options.wrap) {
var label = enter
.append('label')
.attr('class', 'form-label')
.attr('for', function(d) { return 'preset-input-' + d.id; })
.attr('for', function(d) { return 'preset-input-' + d.safeid; })
.text(function(d) { return d.label(); });
var wrap = label
+2 -2
View File
@@ -103,7 +103,7 @@ export function uiFieldCheck(field, context) {
.append('input')
.property('indeterminate', field.type !== 'defaultCheck')
.attr('type', 'checkbox')
.attr('id', 'preset-input-' + field.id);
.attr('id', 'preset-input-' + field.safeid);
enter
.append('span')
@@ -113,7 +113,7 @@ export function uiFieldCheck(field, context) {
if (field.type === 'onewayCheck') {
enter
.append('a')
.attr('id', 'preset-input-' + field.id + '-reverser')
.attr('id', 'preset-input-' + field.safeid + '-reverser')
.attr('class', 'reverser button' + (reverserHidden() ? ' hide' : ''))
.attr('href', '#')
.append('span')
+1 -1
View File
@@ -291,7 +291,7 @@ export function uiFieldCombo(field, context) {
input = input.enter()
.append('input')
.attr('type', 'text')
.attr('id', 'preset-input-' + field.id)
.attr('id', 'preset-input-' + field.safeid)
.call(utilNoAuto)
.call(initCombo, selection)
.merge(input);
+1 -1
View File
@@ -27,7 +27,7 @@ export function uiFieldText(field, context) {
function i(selection) {
var fieldId = 'preset-input-' + field.id;
var fieldId = 'preset-input-' + field.safeid;
input = selection.selectAll('input')
.data([0]);
+1 -1
View File
@@ -39,7 +39,7 @@ export function uiFieldLocalized(field, context) {
input = input.enter()
.append('input')
.attr('type', 'text')
.attr('id', 'preset-input-' + field.id)
.attr('id', 'preset-input-' + field.safeid)
.attr('class', 'localized-main')
.attr('placeholder', field.placeholder())
.call(utilNoAuto)
+2 -2
View File
@@ -33,13 +33,13 @@ export function uiFieldMaxspeed(field, context) {
.container(context.container())
.data(['km/h', 'mph'].map(comboValues));
input = selection.selectAll('#preset-input-' + field.id)
input = selection.selectAll('#preset-input-' + field.safeid)
.data([0]);
input = input.enter()
.append('input')
.attr('type', 'text')
.attr('id', 'preset-input-' + field.id)
.attr('id', 'preset-input-' + field.safeid)
.attr('placeholder', field.placeholder())
.call(utilNoAuto)
.call(combobox)
+1 -1
View File
@@ -20,7 +20,7 @@ export function uiFieldTextarea(field) {
input = input.enter()
.append('textarea')
.attr('id', 'preset-input-' + field.id)
.attr('id', 'preset-input-' + field.safeid)
.attr('placeholder', field.placeholder() || t('inspector.unknown'))
.attr('maxlength', 255)
.call(utilNoAuto)
+1 -1
View File
@@ -91,7 +91,7 @@ export function uiFieldWikipedia(field, context) {
.append('input')
.attr('type', 'text')
.attr('class', 'wiki-title')
.attr('id', 'preset-input-' + field.id)
.attr('id', 'preset-input-' + field.safeid)
.call(utilNoAuto)
.merge(title);
+1 -1
View File
@@ -37,7 +37,7 @@ export function uiFormFields(context) {
// Enter
var enter = fields.enter()
.append('div')
.attr('class', function(d) { return 'wrap-form-field wrap-form-field-' + d.id; });
.attr('class', function(d) { return 'wrap-form-field wrap-form-field-' + d.safeid; });
// Update
fields = fields