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

With sanitizeInput update is immediately called even without user interaction #135

Closed
RobIsHere opened this issue Dec 21, 2016 · 3 comments

Comments

@RobIsHere
Copy link

When I specify sanitizeInput, there is immediately a call to update. That is particularly bad in situations with a disabled text input.

E.g.
{{one-way-input layer.startEffect.duration disabled=layer.startEffect update=(action (mut layer.startEffect.duration))}}
Throws an error with sanitizeInput, because layer.startEffect does not yet exist.

There is also a situation where sanitizeInput causes the creation of 40 records just because the user opens a tab, where the inputs are located. By doing this - without typing anything - the update calls are fired immediately.

Without sanitizeInput everything is back to normal

@RobIsHere
Copy link
Author

More investigation on this: the problem is undefined !== null. I want to cast empty input fields to null on sanitizeInput. That causes the update. Regardless: what I expected was sanitize only driven by user interaction.

I fixed it this way:
(components/one-way-input.js)
`
import Ember from 'ember';
import OneWayInput from 'ember-one-way-controls/components/one-way-input';
import { invokeAction } from 'ember-invoke-action';

const {
Component,
assert,
computed,
get,
isNone,
run: { schedule }
} = Ember;

export default OneWayInput.extend({

_processNewValue(rawValue, noUpdate) {
    let value = invokeAction(this, 'sanitizeInput', rawValue);
    console.log(get(this, '_value'), value, rawValue);

    if (!noUpdate && get(this, '_value') !== value) {
        invokeAction(this, 'update', value);
    }
    schedule('afterRender', this, '_syncValue');
},

didReceiveAttrs() {
    this.__proto__._super(...arguments);
    this._processNewValue(get(this, '_value'), true);
}

});
`

@ghost
Copy link

ghost commented Jan 5, 2017

I removed sanitizeInput and the processNewValue call in the didReceiveAttrs hook. This should fix your problem.

@ghost ghost closed this as completed Jan 5, 2017
@bgentry
Copy link

bgentry commented Jan 5, 2017

@martndemus thanks for your fixes! ✌️

This issue was closed.
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

2 participants