jonjamz / blaze-forms

Dead easy reactive forms with validation (Meteor).
https://atmospherejs.com/templates/forms
MIT License
113 stars 11 forks source link

this.refresh() in onDataChange helper does not refresh the html form fields #105

Open Kshatra opened 7 years ago

Kshatra commented 7 years ago

It seems that this.refresh() in onDataChange helper does not refresh the html form fields, though setting original values to new values. Seems like the issue is in this part of module.js code:

// Update reactiveValue without tracking it.
return Tracker.nonreactive(function () {

    // If the remote value is different from what's in initial data, set `newRemoteValue`.
    // Otherwise, leave it--the user's edits are still just as valid.
    if (!_.isEqual(component.value.get(), fieldValue)) {
        component.newRemoteValue.set(fieldValue);

        // Allow for remote data changes to pass through without user action.
        // This is important for the experience of some components.
        if (component.passThroughData) {
            component.refresh();
        } else {
            component.remoteValueChange.set(true);
            component.refresh(); //only refreshes if add this line
        }
    }
});

I've managed to get html input refresh by applying component.refresh() also in the else clause of if (component.passThroughData).

Kshatra commented 7 years ago

The problem is newRemoteValue in Tracker.nonreactive call is set after the onDataChange's refresh call and reactive refresh never happens again after that. That is because Tracker.afterFlush somehow execures before newRemoteValues is set.