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

Fix form auto submit #35

Closed
wants to merge 2 commits into from
Closed

Fix form auto submit #35

wants to merge 2 commits into from

Conversation

sirodoht
Copy link

When the pell editor exists inside a form, clicking on the actions triggers the form submission. This happens due to this line.

Not sure why this behaviour happens, but returning false stops it.

Here is an example to demonstrate this behaviour:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Pell Bug Demostration</title>
    <link rel="stylesheet" type="text/css" href="https://unpkg.com/pell/dist/pell.min.css">
    <style>
        .pell-editor {
            height: 100px;
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <form action="/submit/" method="post">
        <div class="item">
            <label for="title">Title:</label>
            <input type="text" name="title" id="title" required>
        </div>
        <div class="item">
            <label for="description">Description:</label>
            <textarea name="description" cols="50" rows="3" id="description"></textarea>
        </div>
        <div class="item">
            <label for="pell">Text:</label>
            <div id="pell"></div>
        </div>
        <input type="submit" value="Submit">
    </form>
    <script src="https://unpkg.com/pell"></script>
    <script>
        pell.init({
            actions: [
                'bold',
                { name: 'italic', icon: '&#9786;', title: 'Zitalic' },
                'underline'
            ],
            classes: {
                actionbar: 'pell-actionbar',
                button: 'pell-button',
                editor: 'pell-editor'
            },
            onChange: html => {
                document.getElementById('text-output').innerHTML = html
                document.getElementById('html-output').textContent = html
            },
            root: 'pell'
        })
    </script>
</body>
</html>

@danielsamuels
Copy link

It's because they're <button> elements with no type attribute, which means they default to being submit. Adding a type of 'button' should also fix it.

@sirodoht
Copy link
Author

@danielsamuels aha! I see, thank you.

@vishr vishr mentioned this pull request Aug 17, 2017
@sirodoht sirodoht closed this Oct 15, 2017
@DisableAsync
Copy link

and the solution is add root: 'pell' in the init section?
i cant find other changes

@sirodoht
Copy link
Author

@CingKong The solution is to add type=button HTML attribute on the buttons.

@DisableAsync
Copy link

Okay, I kept trying to find it out from your post, and ignored @danielsamuels ' comment.
Thanks.

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

Successfully merging this pull request may close these issues.

None yet

3 participants