formly-js / angular-formly

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

Expression property is not evaluated #634

Open slavafomin opened 8 years ago

slavafomin commented 8 years ago

Hello!

I have the following form type:

formlyConfigProvider.setType([
  {
    name: 'button',
    templateUrl: 'templates/form/types/button.html',
    defaultOptions: {
      templateOptions: {
        type: 'button',
        disabled: false
      },
      expressionProperties: {
        'templateOptions.disabled': 'form.$invalid || !form.modified'
      }
    }
  }
]);

However, when I use it in my application the template option is not updated when the value of form.modified property changes.

This property is added to the form controller by the angular-input-modified module.

If I replace the expression with the function, I can see that it's not called when the form.modified property changes.

Do you know what could cause this and how can I make it work? Thank you!

slavafomin commented 8 years ago

Update.

I've added model: 'form' property to the specific field and it helped.

It looks like expressions properties are updated when model changes and in my case I don't have a model, cause it's just a button. So when I passed form controller instead of the model it began to see the changes.

I've tried to put this property on the form type level, e.g. inside of defaultOptions object, but it's not working that way.

Is there a way to fix this on a global level, i.e. in entire library or at least in form type? Maybe we should implement a property for the form type configuration, e.g. watchFormChanges: true or something?

Thanks!

kentcdodds commented 8 years ago

Could you please reproduce your issue using issue.angular-formly.com? It will help us determine what exactly the problem is that you're describing and how it could be fixed. Thanks!

kwypchlo commented 8 years ago

Hey @slavafomin, check out this thread to get the idea how to get around your issue https://github.com/formly-js/angular-formly/issues/672

You can define custom watcher on a form that will evaluate expressionProperties or if you dont have model, then even better just set watchAllExpressions on form options to true and be done with it :)

slavafomin commented 8 years ago

Hello @kwypchlo , thank you for the suggestion. I will try it in the future, if I will stumble upon this issue again.