Dynamic field binding in Lightning (e.g. lightning:input)

We understand that the ergonomics from a declarative point of view are great, but unfortunately there are big performance penalties and a bunch of quirks and functional issues supporting dynamic evaluation of expressions (ex. what would happen if you were to mutate the binding (bidirectional) in the children? - it will be very hard to mutate the object back given the dynamic expression).

Moreover, this approach will only solve very simple use cases, if you want to do any transformation or filtering, you will have to jump anyway to imperative code.

Here is a trivial workaround to achieve the same result:

({
  init: function (cmp) {
    var fields = Object.keys(cmp.get('v.record'));
    var filteredFields = fields.filter(function (f) { ... }) 
    cmp.set('v.filteredFields', filteredFields);
  }
})

Because of all of what I stated previously, I don't think this feature will be likely to be prioritized, at least not until we refactor the internals of how the expressions work.


One can use the "getReference" function to programmatically create the dual binding between a record's field and its UI input. That way, as someone updates the inputs, the fields' values on the record are also automatically updated. Then one can validate and save as necessary later by inspecting the record(s) instead of potentially each UI input.

// Basic Usage Sample Code
var recordFieldReference = cmp.getReference('v.record.' + field.APIName);

inputComponent.set('v.value', recordFieldReference);

I haven't tested this with many records with many columns so how performant it may be is unknown but would like to find out.

See My Field Set Form Stack Overflow Comment For A More Detailed Example That Includes Dynamically Determining the UI Input Based On Type