marco birchler
marco birchler

Reputation: 1746

DevExtreme component is not available in event parameter

Most of the event methods provided by DevExtreme components pass in an event object which has the event-triggering component as a child. In the handling event method I can then just use the component from the event parameter and I don't have to reference the component with the @ViewChild mechanism. In most cases this just works perfectly. However - if I use DxForm to create my form components dynamicall and give the following object to DxForm's items parameter it won't work any more:

[{
   dataField: 'postingText',
   editorType: 'dxAutocomplete',
   editorOptions: {
       dataSource: this._listService.PostingTextDataSource,
       onValueChanged: (changedValue) => this.autocompleteChanged(changedValue) 
   }
}]

My event handling method autocompleteChanged will be called and I get the event object. The event object has also a component child. But this component object is somehow broken:

enter image description here

As you can see the component object has no useful properties. And most of the properties start with an underscore (are they some kind of private/protected?).

What do I wrong? Is it really not possible to get the component this easy?

Upvotes: 0

Views: 1391

Answers (1)

sometimes_elen
sometimes_elen

Reputation: 161

You are right, Form editors don't provide a Form component in their event handlers. They provide only information about themselves (you can check the element parameter as well - it is an editor's element, not a Form's one).

So in your case, the component parameter is an Autocomplete's instance and you have to use the ViewChild decorator.

Alternatively, you can grab the Form's instance from the onInitialized event handler.

They have code snippets in the Angular Components - Call Methods topic.

Upvotes: 1

Related Questions