From 7076bcef1625ef86528dc3a769301cd33c4294d6 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 3 Aug 2017 11:28:10 -0400 Subject: [PATCH] uiField now dispatches own events --- modules/ui/field.js | 8 +++++--- modules/ui/preset_editor.js | 14 +++++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/ui/field.js b/modules/ui/field.js index 58caa4018..74364fb83 100644 --- a/modules/ui/field.js +++ b/modules/ui/field.js @@ -4,10 +4,12 @@ import { textDirection } from '../util/locale'; import { svgIcon } from '../svg'; import { uiFields } from './fields'; import { uiTagReference } from './tag_reference'; +import { utilRebind } from '../util'; -export function uiField(context, dispatch, presetField, entity, show) { - var field = _.clone(presetField), +export function uiField(context, presetField, entity, show) { + var dispatch = d3.dispatch('change'), + field = _.clone(presetField), tags; @@ -157,6 +159,6 @@ export function uiField(context, dispatch, presetField, entity, show) { }; - return field; + return utilRebind(field, dispatch, 'on'); } diff --git a/modules/ui/preset_editor.js b/modules/ui/preset_editor.js index f87c08251..3ad1ce88d 100644 --- a/modules/ui/preset_editor.js +++ b/modules/ui/preset_editor.js @@ -47,24 +47,32 @@ export function uiPresetEditor(context) { preset.fields.forEach(function(field) { if (field.matchGeometry(geometry)) { fieldsArr.push( - uiField(context, dispatch, field, entity, true).tags(tags) + uiField(context, field, entity, true) ); } }); if (entity.isHighwayIntersection(context.graph()) && presets.field('restrictions')) { fieldsArr.push( - uiField(context, dispatch, presets.field('restrictions'), entity, true).tags(tags) + uiField(context, presets.field('restrictions'), entity, true) ); } presets.universal().forEach(function(field) { if (preset.fields.indexOf(field) === -1) { fieldsArr.push( - uiField(context, dispatch, field, entity).tags(tags) + uiField(context, field, entity) ); } }); + + fieldsArr.forEach(function(field) { + field + .tags(tags) + .on('change', function(t, onInput) { + dispatch.call('change', field, t, onInput); + }); + }); } var shown = fieldsArr.filter(function(field) { return field.isShown(); }),