Autoform refuses to carry out form submission

I’m working on url shortener application where I use Bitly’s service to shorten urls and pass them into the database using Autoform’s autoValue property along with the user submitted url. Now when I enter a valid url and press submit nothing happens! I get no errors in the console and everything is well defined.

Here’s the schema:

import SimpleSchema from 'simpl-schema';
import { Tracker } from 'meteor/tracker';
// Required AutoForm setup
SimpleSchema.extendOptions(['autoform']);
SimpleSchema.debug = true;


Links = new Mongo.Collection("links");

LinksSchema = new SimpleSchema({
  url: {
    type: String,
    label: 'Input',
    regEx: SimpleSchema.RegEx.Url,
    index: true,
    unique: true,
     autoform: {
      afFieldInput: {
      type: "url",
      placeholder: "Place your links here...",
    }
    }
  },
  encodedUrl: {
      type: String,
      optional: true,
      autoValue: function() {
        var url = this.field("url");
        
       if (url.isSet) {
       return Meteor.call("getBitlyUrl", url.value );
       } else {
           this.unset();
       }
        }
  } 
   
}, { tracker: Tracker });

Links.attachSchema(LinksSchema);

the method:

import Bitly from 'bitly';
const bitly = new Bitly( Meteor.settings.private.bitly );

Meteor.methods({
  getBitlyUrl( url ) {
      return bitly.shorten( url ).then( ( response ) => {
        return response;
      });
    
  }
});

and keep in mind that I import the method and the collection into the server side on startup:

import '../../api/collections/links.js';
import '../../api/methods/bitly.js';

I managed to solve the problem, too bad I don’t know how to delete or terminate this thread.

For anyone who’s running into this same problem where the form won’t submit, it has to do with one of the fields being incomplete or empty (encodedUrl in this case). To fix it I had to perform the getBitlyUrl method on the server, providing the url myself, and see what type of response it returned. Turns out it returns an entire object instead of just a string, so I simply had to modify the method to grab the encoded url only. I hope the included images help you figure out what I did if I failed to explain, thanks!meteor3
Calling this line below in main.js in the server folder to figure out what’s the actual output of the method


  console.log(Meteor.call('getBitlyUrl', 'https://github.com/asveloper/shortner/blob/master/server/service.js'));
1 Like