formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

hideExpression missing formOptions #616

Closed chilversc closed 8 years ago

chilversc commented 8 years ago

When evaluating a hideExpression there is no formOptions variable.

This means there is no simple way to reference the formOptions.data field and leads to the odd scenario where to access the form options you use this.options but to access the field options you use just options.

I think the only change required would be to add formOptions: $scope.options to the getFormlyFieldLikeLocals function.

kentcdodds commented 8 years ago

Technically this should have almost everything that this has. I think the only thing that's missing is: originalModel, and formOptions. The other properties are actually properties on the $scope of the formly-form which is where the expression is evaluated and therefore you should have access to it in your expression.

I'd happily accept a (tested) PR to add these properties. If you're keen on it, that's great. If you need help, maybe someone from @formly-js/angular-formly-collaborators or @formly-js/angular-formly-collaborators-read could give you a little guidance. Thanks everyone!

nikhilshagri commented 8 years ago

I would like to create a PR for this bug. I am new to this project and have browsed through the formly docs a bit, and I have a basic understanding about this project now.

kentcdodds commented 8 years ago

Great, you might take a look at the CONTRIBUTING.md file as well :+1:

nikhilshagri commented 8 years ago

Ok, I dug into the docs and found that adding formOptions: $scope.options probably won't work because hideExpression is evaluated against the form scope instead of the field scope. I will have to try to find if the field scope has been initialized or not and then obtain it's scope via its index.( Or at least, this is how I think it should be :P ). As for the originalModel property, I am assuming that it will contain the field's model.

kentcdodds commented 8 years ago

Yeah, originalModel can simply be: $scope.model (the form's $scope). formOptions will need to be $scope.options (the form's $scope)...

nikhilshagri commented 8 years ago

Ok, got it. Will submit a PR soon.

sukrosono commented 8 years ago

since it merged, we should close this one?

kentcdodds commented 8 years ago

Yep! Feel free to close it. Thanks!

sukrosono commented 8 years ago

@kentcdodds maybe i don't get the right? or i missing something. even add label i can't do it. :smile: