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';