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

input value isn't reset if onsubmit event is triggered with enter #288

Closed
ghost opened this issue Sep 29, 2014 · 6 comments
Closed

input value isn't reset if onsubmit event is triggered with enter #288

ghost opened this issue Sep 29, 2014 · 6 comments
Labels
Type: Bug For bugs and any other unexpected breakage

Comments

@ghost
Copy link

ghost commented Sep 29, 2014

I am writing a simple chat application with mithril. It has a form to enter the message with a onsubmit handler in which the input value is reset. The strange thing is that it works if the event handler is triggered with a click on the submit button; however, it does not if it is triggered by hitting enter. Interestingly, if I add the property to a debug span element, it is updated in both cases.

Tested in latest Chrome and Firefox.

Code:

<!doctype html>
<script src="mithril.js"></script>
<script>
    var chat = {};
    chat.Message = function (text) {
        this.text = m.prop(text);
    };
    chat.MessageList = Array;

    chat.vm = {};
    chat.vm.init = function () {
        this.list = new chat.MessageList();
        this.messageText = m.prop("");

        this.post = function () {
            if (this.messageText()) {
                this.list.push(new chat.Message(this.messageText()));
                this.messageText("");
            }
            return false;
        }.bind(this);
    };

    chat.controller = function () {
        chat.vm.init();
    };

    chat.view = function () {
        return m("html", [
            m("body", [
                m("form", {onsubmit: chat.vm.post}, [
                    m("ul", chat.vm.list.map(function (message) {
                        return m("li", {}, message.text())
                    })),
                    m("input[type=text]", {oninput: m.withAttr("value", chat.vm.messageText), value: chat.vm.messageText()}),
                    m("span", chat.vm.messageText()),
                    m("button[type=submit]")
                ])
            ])
        ]);
    };

    m.module(document, chat);
</script>
@ghost ghost changed the title input value isn't reset if onsubmit event triggered with enter input value isn't reset if onsubmit event is triggered with enter Sep 29, 2014
@bsuh
Copy link
Contributor

bsuh commented Sep 29, 2014

http://jsfiddle.net/ux359kpy/

Seems like it has to do with the fix for #214. When you press enter, the input retains focus and the value isn't "clobbered"/updated.

@kvanbere
Copy link

Nevermind, it doesn't work for me either, but does with v21.

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

lhorie commented Sep 30, 2014

So yeah, I had good convo w/ @bsuh yesterday. Basically, the problem was that I used a hacky workaround to fix #151, which then required another hacky workaround to fix #214, which is now causing this, in a silly domino effect. I'm going to revert the changes to deliberately break #151 again, because now we can use m.redraw.strategy from application space to prevent double redraws. This should restore correct functionality for both #214 and #288

@kvanbere
Copy link

Is this going to fix not being able to type into some input fields on
Safari for iOS?

On Tue, Sep 30, 2014 at 11:08 PM, Leo Horie notifications@github.com
wrote:

So yeah, I had good convo w/ @bsuh https://github.com/bsuh yesterday.
Basically, the problem was that I used a hacky workaround to fix #151
#151, which then required
another hacky workaround to fix #214
#214, which is now causing
this, in a silly domino effect. I'm going to revert the changes to
deliberately break #151 #151
again, because now we can use m.redraw.strategy from application space to
prevent double redraws. This should restore correct functionality for both
#214 #214 and #288


Reply to this email directly or view it on GitHub
#288 (comment).

bsuh added a commit to bsuh/mithril.js that referenced this issue Oct 1, 2014
lhorie pushed a commit that referenced this issue Oct 2, 2014
…olve double-redraws in onkeypress+oninput
@lhorie
Copy link
Member

lhorie commented Oct 2, 2014

So the issue here was that a non-ideal workaround for #151 caused #214, and the non-ideal workaround for #214 caused this. I'm reverting the workarounds because #151 can be resolved in application space w/ m.redraw.strategy("none") and there's no other reasonable way to fix #214 and #288.

This will take effect on the next release (0.1.23)

@lhorie lhorie closed this as completed Oct 2, 2014
@ghost
Copy link
Author

ghost commented Oct 2, 2014

@lhorie, thank you! How regularly is mithril released?

lhorie added a commit that referenced this issue Oct 2, 2014
bsuh added a commit to bsuh/mithril.js that referenced this issue Oct 3, 2014
lhorie added a commit that referenced this issue Nov 13, 2014
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