Reputation: 2426
I have a user schema, the user may have a list of teams as shown in this part:
"teams": {
type: [Object],
optional: true,
autoform: {
label: "Teams",
'label-type': 'stacked',
afFieldInput: {
type: "tokenInput"
}
}
},
"teams.$.name": {
type: String,
optional: true,
autoform: {
ommit: true
}
},
"teams.$.address": {
type: String,
optional: true,
autoform: {
ommit: true
}
},
I want to use a simple custom field I created using jQuery token input:
AutoForm.afTeams("tokenInput", {
template: "afTokenInput",
valueOut: function () {
return $("#tokenInput").tokenInput('get');
}
});
Template.afTeams.rendered = function() {
token();
function token() {
$("#tokenInput").tokenInput('/api/teams/?q', {
onReady: function() {
console.log('Ready...');
},
preventDuplicates: true,
minChars: 3,
propertyToSearch: 'name'
});
}
}
Template:
<template name="afTokenInput">
<input id="tokenInput" class="token" type="text" />
</template>
I want to only show the jQuery token input, for teams field, and then return an Array of objects when submitting.
My template get rendered only if the type of teams in the schema is String but for Array of objects it renders the standard afArrayField and afObjectField.
https://i.sstatic.net/MsxIK.png
Is there a way to override this ? to:
https://i.sstatic.net/VNFGe.png
Upvotes: 2
Views: 358
Reputation: 2426
I had to put the type in autoform object:
"teams": {
type: [Object],
optional: true,
autoform: {
type: "tokenInput",
label: "Teams",
'label-type': 'stacked'
}
},
And put {{atts}} somewhere in template to trigger valueOut:
<template name="afTokenInput">
<input type="hidden" {{atts}} />
<input id="tokenInput" class="token" type="text" />
</template>
Upvotes: 0
Reputation: 392
This might work:
afQuickField: {
type: "tokenInput"
}
And make sure to use "omit" instead of "ommit" in "name" and "address" fields
Upvotes: 1