Two-way form meteor for form validation

I read a lot of resources about Blaze that allow me to respond to rendering for Meteor 0.8, but I can’t find a solution for my simple problem below.

I am trying to check my form inputs. For the sake of simplicity, let's say that I just want to change my own {{message}}when submitting the form. The approach I used in client.jsjust gives a new value to the helper variable. This is how I worked with AngularJS, but it seems to be more than just changing a variable in Meteor. How can i do this?

- index.html
<template name="user">
    <form>
        <input type="text" id="name">
        <p>{{message}}</p>
        <button class="submit" onclick="return false;">Submit</button>
    </form>
</template>

- client.js
Template.user.message = "";
Template.user.events = {
    'click .submit' = function(){
        Template.user.message = "valid";
    }
}
+4
source share
1 answer

, . :

Template.user.message = function() {
  return Session.get('userMessage');
};

Template.user.events({
  submit: function() {
    Session.set('userMessage', 'valid');
  }
});

, events ( , ).

+1

Source: https://habr.com/ru/post/1537430/


All Articles