-
Notifications
You must be signed in to change notification settings - Fork 401
fix relative string models in hideExpression and watchers #639
fix relative string models in hideExpression and watchers #639
Conversation
Current coverage is
|
Hi @kwypchlo! Thanks for making this. I'll review it more closely soon. But if you could double check the commit message conventions, I don't think this follows it. Also, pay close attention to what you need to do in the commit message if you're introducing a breaking change please. Thanks! |
f9e389d
to
e68c568
Compare
Yeah @kentcdodds I've just edited the message :) it took me a while to prepare this PR and I noticed I didn't conform with commit message standard just after I pushed the PR. |
Awesome. Thanks for doing that! I'll get back to you soon hopefully! |
@@ -366,6 +368,9 @@ function formlyForm(formlyUsability, formlyWarn, $parse, formlyConfig, $interpol | |||
function getFormlyFieldLikeLocals(field, index) { | |||
// this makes it closer to what a regular formlyExpression would be | |||
return { | |||
// when field.model is not yet an object, this call should be evaluated in $scope.model context | |||
// because this is a call where field.model gets resolved | |||
model: angular.isObject(field.model) ? field.model : $scope.model, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should actually put this logic in the place where the field model gets resolved rather than here because it could lead to unexpected results in other expressions.
I think this PR is great other than the one note that I mentioned. Let me know if you have questions about that. |
@kentcdodds yeah sorry I'm just super busy right now :) You are right, I will refactor this piece of code when I get a chance and ping you afterwards |
… watcher expression for nested models BREAKING CHANGE: reference to 'model' in string hideExpressions and watchers on fields with nested models now points to field.model just as in expressionProperties
e68c568
to
c899ee6
Compare
@kentcdodds I've updated this PR with some refactoring. Now |
Looks good to me! Thoughts @formly-js/angular-formly-collaborators-read? |
fix relative string models in hideExpression and watchers
Hopefully the auto-release works for this one. We've had a bit of trouble with that recently. |
cool, thanks @kentcdodds |
Nope :-( #643 is tracking issues with the auto-release process... |
What
Previously discussed on my previous PR #599 (comment)
expect breaking change
String hideExpression and watchers were evaluated in context of
$scope.model
unlike expressionProperties that were evaluated in the context of the model of a field. That said when you had nested model likeconst model = {nested: {foo: 'bar'}};
and your field would have model declared as a stringmodel: 'model.nested'
your hideExpression and watcher would vary from expressionProperties:After my tweaks, watchers and hideExpressions that are string-based, are evaluated in the same model context as expressionProperties which is only logical.
Why
'model.' + key
which didn't work out of a box for nested models because fe.const model = {nested: {foo: 'bar'}};
withmodel: 'model.nested'
, watcherExpression would bemodel.foo
because ofwatchExpression = 'model[\'' + field.key.toString().split('.').join('\'][\'') + '\']'
and this would not work because it didn't take into account that model was moved to nested child and would expectmodel.nested.foo
to workHow
I have added 2 things:
Checklist:
I might add a test or two to confirm watchers behavior but wanted to post this PR for first review