qontu / ngx-inline-editor

Native UI Inline-editor Angular (4.0+) component
https://qontu.github.io/ngx-inline-editor
MIT License
164 stars 90 forks source link

Added fields name to state object #72

Closed Hotzilla closed 7 years ago

Hotzilla commented 7 years ago

In many cases you have single save-function, that is referenced by multiple onSave() events. In these cases you want to know which field actually passed the save event. It was possible to fetch this info through DOM, but it was bit too complex.

Added optional "name" property to state object, which can be easily used to identify which field sent the event.

I tested this code in my own project.

tonivj5 commented 7 years ago

Thanks for your contribution @Hotzilla 👍, it's a good catch, but I think to pass name into state object is not the better. I think we should pass the instance of the inline-editor through ExternalEvent/InlineEvent. Something like this:

this.events.external.onChange.emit({
   event,
   instance: this, // instance/inlineEditor or something so
   state,
})

Because you need information about inline-editor instance, but if I need more information (ex,size), We should add size property into state and it is not its mission. State should show properties of input that can change the stateof input (for example, if you disabled an input, the input will be not writtable).

Then, when I receive the $event I can get event.instance.name, event.instance.size, etc.

Does it fulfills your need?

Hotzilla commented 7 years ago

Sure, editor instance works as well and has more wider use cases. It probably should also be in onSave emit, so it is easy to use.

tonivj5 commented 7 years ago

Hi @Hotzilla it will be implemented in https://github.com/qontu/ngx-inline-editor/pull/76 and this PR can be closed 👍

Thanks for your interest 😉

tonivj5 commented 7 years ago

This feature can you use it with version 0.2.0-alpha.5

When an event is triggered, if onlyValue is false, the event (an InlineEditorEvent) will have a property named instance. It is a reference of inline-editor component which triggered the event.