Detect change in text field

Forums: 

Hi,

I am building a new widget. It is possible to pass the widget a path to a text field.

How can I detect when this text field is modified ?

I thought I could use H5PEditor.followField but i get an error saying that this field can't be followed.

Thanks.

(it seems to work for select, but not for text)

otacke's picture

Unfortunately, the core editor widgets are not all behaving the same way - that might need some tidying. For a text field, you can push your callback functions to changeCallbacks (https://github.com/h5p/h5p-editor-php-library/blob/master/scripts/h5peditor-text.js#L15) directly or (if the jQuery change listener doesn't suffice) add your own listeners to the text input field ($input).

Thanks ! Maybe followField should fall back to changeCallbacks if changes doesn't exist. I don't know if this would have any side effect.

otacke's picture

Wouldn't that be patchwork introducing unnecessary complexity and confusion with two variables for the same thing. I'd prefer if changeCallbacks would simply be marked as deprecated, that text widget would move to changes and just go on to support changeCallbacks for a while before it's removed.

That would be indeed better. I created an issue : https://github.com/h5p/h5p-editor-php-library/issues/129