简体   繁体   中英

Meteor preventDefault() function not working

So I am having this issue where prevent default is not working on my web application. Js I am very new to meteor. Here is my body.js

import { Template } from 'meteor/templating';
import '../body.html';

Template.newround.events({
  'submit .new-round'(event) {
    event.preventDefault();

    console.log("test");
  },
});

just ask if you need any other info.

HTML:

<body>

  <div class="container-fluid">

    <div class="row" style="display: flex; justify-content: center; align-items: center; min-height: 100%;">

      <div class="col-md-3"><!--  --></div>

      <div class="col-md-6">

        <div class="panel panel-default">
          <div class="panel-body">
            <h1 class="center-text">Welcome to FightBot!</h1>
            <p class="center-text">With FightBot you can increase your reaction time! Lets begin!</p>
          </div>

          <hr>

          <div class="panel-body">

            {{> newround }}

          </div>

        </div>

      </div>

      <div class="col-md-3"><!--  --></div>

    </div>

  </div>

</body>

<template name="newround">

<form class="new-round">

  <p>Seconds between strikes:</p>

  <input type="text" class="form-control" name="seconds">

  <br>

  <input type="submit" class="btn btn-success pull-right" value="Start">

</form>

</template>

That's all the html if anything else is needed just ask.

I guess that newround is a template that contain a form, and event.preventDefault() should prevent the default behavior (preventing the form from being submitted). It assume that you will handle the submission yourself. The console.log("test") line should still get executed. What is not working?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM