From 033636629a1f3be8d7f8792f8a8be3d5a26cf744 Mon Sep 17 00:00:00 2001 From: Jonny Buchanan Date: Wed, 8 Apr 2015 21:44:21 +0100 Subject: [PATCH] When given a fieldRef callback, pass widgets a ref callback and call the given callback with additional field and form details --- src/BoundField.js | 5 +++++ src/Form.js | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/BoundField.js b/src/BoundField.js index 31a1b0d..77bca29 100644 --- a/src/BoundField.js +++ b/src/BoundField.js @@ -198,6 +198,11 @@ BoundField.prototype.asWidget = function(kwargs) { if (typeof attrs.key == 'undefined') { attrs.key = name } + if (this.form.fieldRef) { + attrs.ref = (ref) => { + this.form.fieldRef(ref, this.name, this.form) + } + } var validation = this._getValidation(widget) diff --git a/src/Form.js b/src/Form.js index f318f0b..2198baf 100644 --- a/src/Form.js +++ b/src/Form.js @@ -58,7 +58,7 @@ var Form = Concur.extend({ data: null, files: null, autoId: 'id_{name}', prefix: null, initial: null, errorConstructor: ErrorList, labelSuffix: ':', emptyPermitted: false, validation: null, controlled: false, - onChange: null, errors: null + onChange: null, errors: null, fieldRef: null }, kwargs) this.isInitialRender = (kwargs.data == null && kwargs.files == null) this.data = kwargs.data || {} @@ -72,6 +72,7 @@ var Form = Concur.extend({ this.emptyPermitted = kwargs.emptyPermitted this.controlled = kwargs.controlled this.onChange = kwargs.onChange + this.fieldRef = kwargs.fieldRef // Auto validation is implied when onChange is passed if (is.Function(kwargs.onChange)) {