Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derived property "data" should emit "change" events #69

Open
countzero opened this issue Dec 8, 2016 · 1 comment
Open

Derived property "data" should emit "change" events #69

countzero opened this issue Dec 8, 2016 · 1 comment

Comments

@countzero
Copy link

As a developer, I want to create a form view and only listen to changes of its "data" property, so that I can conveniently handle data changes.

This is especially useful for forms that autosave on data change and forms with dynamic fields.

Currently the "data" property is a cached derived property that will never emit any events. The documentation states otherwise:

https://www.npmjs.com/package/ampersand-form-view#properties

The following are FormView observables, thus emit "change" events:

valid - the valid state of the form
data - form field view values in { fieldName: value, fieldName2: value2 } format

Possible solution: Extend the update method to also trigger a "change" event passing the "data" property.

@countzero
Copy link
Author

A possible workaround until this feature is implemented:

'use strict';

var AmpersandFormView = require('ampersand-form-view');

/**
 * Form View
 *
 * @see https://github.com/AmpersandJS/ampersand-form-view/blob/v7.0.0/ampersand-form-view.js
 * @see https://github.com/AmpersandJS/ampersand-form-view/issues/69
 */
module.exports = AmpersandFormView.extend({

    /**
     * Monkey patch the update method to trigger "change"
     * events on the cached derived property "data".
     *
     * @param {string} field The form fields.
     */
    update: function (field) {

        AmpersandFormView.prototype.update.call(this, field);

        this.trigger('change change:data', this.data);
    },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant