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

Changing value from "" to 0 doesn't update DOM #379

Closed
tivac opened this issue Dec 5, 2014 · 5 comments
Closed

Changing value from "" to 0 doesn't update DOM #379

tivac opened this issue Dec 5, 2014 · 5 comments
Labels
Type: Bug For bugs and any other unexpected breakage

Comments

@tivac
Copy link
Contributor

tivac commented Dec 5, 2014

http://jsbin.com/susifidowo/1/edit?js,output

We ran into an issue with text fields that are numeric, but able to blanked out (such as a user clearing the field before entering a new value). If the value is an empty string, and we then try to set the value to 0 and re-render the diff is empty and the result doesn't change.

Repro:

  1. Load JsBin
  2. Note empty input
  3. Click "zero" button, note input contains 0.
  4. Click "value" button, note input contains 125.
  5. Click "empty" button, note input is empty.
  6. Click "zero" button, note input remains empty.
  7. Click "value" button, note input contains 125

Expected:
When input is empty and the value is change to 0, the input value would change in the next render.

Note: This isn't a problem going from 0 to an empty string, in that case it properly updates the input value.

Repro Code

var model = {
  val : ""
};

//initialize
m.module(document.body, {
  controller : function() {
    this.clickEmpty = function(e) {
      e.preventDefault();

      model.val = "";
    };

    this.clickZero = function(e) {
      e.preventDefault();

      model.val = 0;
    };

    this.clickValue = function(e) {
      e.preventDefault();

      model.val = 125;
    };
  },

  view : function(ctrl) {
    return [ 
      m("input", { value : model.val }),
      m("button", { onclick : ctrl.clickEmpty }, "empty"),
      m("button", { onclick : ctrl.clickZero }, "zero"),
      m("button", { onclick : ctrl.clickValue }, "value")
    ];
  }
});
@Naddiseo
Copy link
Contributor

Naddiseo commented Dec 5, 2014

Perhaps model.val should always be a string. If I use model.val = "0" it works again.

@lhorie lhorie added the Type: Bug For bugs and any other unexpected breakage label Dec 6, 2014
@lhorie
Copy link
Member

lhorie commented Dec 6, 2014

related to #367

@tivac
Copy link
Contributor Author

tivac commented Dec 6, 2014

@lhorie that was my suspicion as well, but figured I'd report any ways. I haven't tracked down where exactly this is running into trouble but I'm hoping I'll be able to look soon.

lhorie added a commit that referenced this issue Dec 6, 2014
@lhorie
Copy link
Member

lhorie commented Dec 6, 2014

Fixed in origin/next

@lhorie lhorie closed this as completed Dec 6, 2014
@tivac
Copy link
Contributor Author

tivac commented Dec 7, 2014

@lhorie awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug For bugs and any other unexpected breakage
Projects
None yet
Development

No branches or pull requests

3 participants