Skip to content
This repository has been archived by the owner. It is now read-only.

Add hide expression on a formField #16

Closed
kentcdodds opened this issue Jun 1, 2014 · 1 comment

Comments

@kentcdodds
Copy link
Member

commented Jun 1, 2014

I want to be able to do something like this:

var formFields = [
  {
    key: 'foo',
    type: 'text'
  },
  {
    key: 'bar',
    type: 'text',
    hideExpression: 'result.foo === "hideBar"'
  }
];
var result = {
  foo: '',
  bar: ''
};

So I can have conditional fields in my form.

@kentcdodds

This comment has been minimized.

Copy link
Member Author

commented Jun 1, 2014

I'm looking into it and I'm not sure of the best approach to take.

I'm thinking that it would be best to add an ng-hide="field.hide" to the <formly-field ng-repeat... in the formly-form template. Then, in the formly-form controller, when initializing the scope, iterate through the fields and add a hide property and add a watcher to the scope for each of the hide expressions. When that watch listener fires, set the field.hide property to the value of the expression.

The trouble I'm having now is: How do we get the scope to evaluate the expression on (watch the expression). I've thought about adding it as another property to the formField but passing scopes around just feels wrong.

Just came up with a much better simpler implementation. Prepare for a pull request...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant
You can’t perform that action at this time.