materialize modal in Meteor how to trigger modal

岁酱吖の 提交于 2019-12-24 15:37:26

问题


I think I'm confused on how to trigger a modal from the Materialize Modal package. Materialize Modal I've got the package loaded and I'd like to use one of the pre-baked modals.

JS:

MaterializeModal.form({
title: "Enter some Data!",
bodyTemplate: "my-form",
callback: function(error, response) {
  if (response.submit) {
    // Iterate over form results & display.
    for (var field in response.form) {
    Materialize.toast(field + ": " + response.form[field], 5000, "green");
  }
  } else {
    Materialize.toast("Cancelled by user!", 5000, "red");
  }
}
});

MaterializeModal.display({
  bodyTemplate: "my-form"
});

And the template:

<template name="my-form">
  <div class="row">
    <div class="input-field col s6">
      <input id="first_name" type="text" name="first-name" class="validate">
      <label for="first_name">First Name</label>
    </div>
    <div class="input-field col s6">
      <input id="last_name" type="text" name="last-name" class="validate">
      <label for="last_name">Last Name</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s12">
      <input disabled id="disabled" type="text" name="disabled-input" class="validate">
      <label for="disabled">Disabled</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s12">
      <input id="password" type="password" name="password" class="validate">
      <label for="password">Password</label>
    </div>
  </div>
  <div class="row">
    <div class="input-field col s12">
      <input id="email" type="email" name="email" class="validate">
      <label for="email">Email</label>
    </div>
  </div>
</template>

If I've got a button, say:

 <button id="client-search" class="someClass">Search</button>

How would the modal be triggered from the button click? Apologies for the dumb question.


回答1:


As per the docs: Specify the Modal ID in button data-target, add the class modal-trigger to the button and register the trigger. See the docs at http://materializecss.com/modals.html

HTML

<button id="client-search" class="modal-trigger">Search</button>

JavaScript

Template.my-form.onRendered({
  $('.modal-trigger').leanModal();
});

There are some caveats though: modals and dropdowns do not work in the latest version of Materialize on Meteor because Meteor uses a crazy old outdated version of jQuery (it seem impossible to change Meteor's jquery version without branching and repackaging your own Meteor distro) and Materialize relies on newer jquery functionality. I worked around this by using an older version of Materialize, specifically poetic:materialize-scss@1.97.1 (SASS version of Materialize).



来源:https://stackoverflow.com/questions/34698655/materialize-modal-in-meteor-how-to-trigger-modal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!