Meteoric - cannot gather information from input fields

46 views Asked by At

I am making an app with ionic framework and for some reason, it doesn't want to get data from user input fields.

HTML

<template name="form">
<form>
    <div class="list">
        <label class="item item-input">
            <input type="text" name="fName" placeholder="First Name">
        </label>
        <label class="item item-input">
            <input type="text" name="lName" placeholder="Last Name">
        </label>
        <label class="item item-input">
            <input type="text" name="phone" placeholder="Phone">
        </label>
    </div>
    <button type="submit">Save Contact</button>
</form>

Javacript

Template.form.events({
    "form submit": function(event, template) {
        var inputFirstName = event.target.fName.value;
        var inputLastName = event.target.lName.value;
        var inputPhone = event.target.phone.value;

        var object = {
            fName: inputFirstName,
            lName: inputLastName,
            phone: inputPhone
        }

        contactList.insert(object);
        return false;
    }
})

I've been using the exact same event handler for many projects, but it seems not to be working with ionic. Any ideas what might be wrong?Thanks

2

There are 2 answers

2
Erick On

Ionic uses angularjs to do the job, the angular way is the two way data binding, you need to set ng-model="varName" in each input and in the top of the form set your controller with ng-controller="muController" then dwfine myController in your javascript and you will be able to acces those variables through $scope.varName. As I told this is two ways, if you change things in template the valie in your scope changes too and you can change values in your javascript and the new values will be show to the user. Hope to be of help.

0
ignite-me On

I cannot believe how stupid the bug was:

'form submit' obviously should have been 'submit form'