I have typeahead input type working for an input field.
I want to be able to use it like I would other [Meteor.ObjectID] types in my schema (or potentially any arrayed type). {{> afQuickField}}
should recognize the array and wrap it in the 'afArrayField' template, giving it the wonderful add/remove buttons and functionality and also returning an array.
Currently, I just get the one instance of the input and an error message on submission saying that this value must be an array.
I'm scouring autoform's code base looking for how this is implemented on other input types, but so far no luck as there's a LOT of code. I would accept just a pointer to the code that does this currently.
More info
I found AutoForm.getInputType
function in autoform-api.js. I may have to overload this to get my desired behavior. Better alternatives are still welcome!
Tried also
So I thought the trick might be it responds to an array of nested schemas. No overload necessary, just put my typeahead field into a separate schema, and nested it in my main schema.
myTypeahead = new SimpleSchema({
item:{
type: Meteor.ObjectID,
autoform: {
type: "typeahead"
},
...
}
});
myMainSchema = new SimpleSchema({
itemId:{
type: [myTypeahead]
}
});
And that set up the ability to add/remove the fields. The down side? Now typeahead is throwing errors like mad.
Exception in template helper: TypeError: Cannot read property 'lastIndexOf' of undefined
at inflectedLabel (/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2125:44)
at SimpleSchema.getDefinition (/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2670:30)
at Object.autoFormGetOptionsForField [as _getOptionsForField] (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:2690:12)
at Object.afOptionsFromSchema (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:1519:12)
at bindDataContext (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
at Blaze._wrapCatchingExceptions (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
at Object.Spacebars.call (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
at /client/template.person.js?684475f8f7f0a8f9fe76ecebd81f50a84a03f24d:142:30
at Blaze._TemplateWith.wrappedArgFunc (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2639:14)
at null.<anonymous> (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2445:26)
Exception in template helper: TypeError: undefined is not a function
at /packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:212:34
at /packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:176:29
at _.each._.forEach (/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:164:22)
at Function._.map._.collect (/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:175:5)
at Object.getSelectOptions (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:211:25)
at getInputData (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:1783:37)
at Object.afFieldInputContext (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:6999:17)
at bindDataContext (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
at Blaze._wrapCatchingExceptions (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
at Object.Spacebars.call (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
Exception in template helper: TypeError: Cannot read property 'class' of undefined
at Object.addClass (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:641:20)
at Object.Template.afTypeahead.helpers.atts (/client/quickForm/autoform-typeahead.js?5037f57aba2aa1b9ec271e4ade183a5d126781e5:43:29)
at bindDataContext (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
at Blaze._wrapCatchingExceptions (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
at Spacebars.call (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
at Spacebars.mustacheImpl (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:108:25)
at Object.Spacebars.attrMustache (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:124:39)
at /client/quickForm/template.autoform-typeahead.js?e749e8ff2e104b2c1b5d2ca1f3f7bf538c5790e7:17:22
at Object.Blaze._withCurrentView (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2043:12)
at Blaze._HTMLJSExpander.def.visitAttributes (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1962:21)
Exception from Tracker afterFlush function: Cannot read property 'atts' of undefined
TypeError: Cannot read property 'atts' of undefined
at Template.afTypeahead.rendered (/client/quickForm/autoform-typeahead.js?5037f57aba2aa1b9ec271e4ade183a5d126781e5:74:16)
at null.<anonymous> (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:3008:21)
at /packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1733:14
at Object.Blaze._withCurrentView (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2043:12)
at /packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1732:15
at Tracker.flush (/packages/tracker.js?517c8fe8ed6408951a30941e64a5383a7174bcfa:448:11)