Skip to content
This repository has been archived by the owner on Apr 30, 2018. It is now read-only.

Add a hook to transform field config before forms are compiled #343

Closed
kentcdodds opened this issue Jun 9, 2015 · 4 comments
Closed

Add a hook to transform field config before forms are compiled #343

kentcdodds opened this issue Jun 9, 2015 · 4 comments

Comments

@kentcdodds
Copy link
Member

Would be handy if formly-form invoked an overridable function in formlyConfig that allowed transforming the field's (adding/removing/modifying) before they're passed to the formly-field directive. This would enable things like https://github.com/formly-js/angular-formly-json-schema and https://github.com/formly-js/angular-formly-siren-action to transform a json schema or siren action stuff into field configuration that formly understands. @ckniffen I think you have done some work on this for your own project. Any thoughts?

@ckniffen
Copy link
Member

ckniffen commented Jun 9, 2015

Actually this would be helpful for when using the same fields array multiple times. Right now I have to clone each copy of the fields config when creating formly-forms in an ng-repeat where each iteration uses the exact same fields array.

@kentcdodds
Copy link
Member Author

Hmmm... Yeah, I suppose that internally we'll do something like this:

const fieldTransform = $scope.options.fieldTransform || formlyConfig.extras.fieldTransform;
if (fieldTransform) {
  $scope.fields = fieldTransform($scope.fields);
}

That way you could either copy them yourself or simply modify them to maintain references to the correct field.

The reason that I bring this up is that if formly-field actually makes a copy for you, then you may be pointing to the field that you create in your controller, but that ends up not being the field that formly actually uses, which could lead to unexpected behavior.

But I think that kind of an implementation in formly-form would be pretty flexible.

@kentcdodds
Copy link
Member Author

I have pushed some tests for this feature. I've actually already developed this feature and gotten all the tests passing locally, but I want to give someone the chance to make their first OSS contribution, so here are some instructions (if you have already contributed to open source, please let someone else take this one):

  • Watch this video to learn what you need to do to get things setup
  • Go to this line and change describe.skip to describe.only
  • Run $ npm test
  • Notice that all the tests are failing
  • Update formlyApiCheck.js to allow the formly-form options to have a fieldTransform that's a function (somewhere around here)
  • Add a function call right after this one in formly-form.js called setupFields and declare it below (probably around setupOptions) where you'll put your logic for initializing the fields (which means you could probably move this to that new function).
  • Implement setupFields to make the tests pass.
  • Once they're passing, change the describe.only to describe so all the tests run.
  • Commit your changes to the src/ directory mentioning issue Add a hook to transform field config before forms are compiled #343 (notice it runs all the tests... twice)
  • Push your changes to your fork, create a PR, get merged, celebrate 🎉

kentcdodds pushed a commit that referenced this issue Jun 12, 2015
#343 Add a hook to transform field config before forms are compiled
@kentcdodds
Copy link
Member Author

Thanks @stevebluck! This has been officially released in 6.14.0!

ccasad added a commit to ccasad/angular-formly that referenced this issue Jun 25, 2015
…butes to same ng-model for multiple directives
DevanB pushed a commit to DevanB/angular-formly that referenced this issue Jul 27, 2015
DevanB pushed a commit to DevanB/angular-formly that referenced this issue Jul 27, 2015
Corrected commit message. Added ability to add custom class to ngTransclude. Fixes formly-js#398.

Added ability to add custom class to ngTransclude. Fixes formly-js#343.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants