-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AccountsTemplates.addFields using dynamic values for select #569
Comments
+1. I can't figure out any way to get reactive data sources in a SELECT using the default templates. It won't work in a Tracker.autorun() block. |
No, I searched for but didn't find them. Thanks! |
@splendido any idea about the best way to validate dynamic selects as per your suggestion in #328 ? |
I think a custom valudation function could be used to pick up values from the collection you're using and check one of those was actually chosen. |
custom validation functions aren't getting run when I use a custom template. |
this is weird... |
This link should illustrate the problem. How can I hook the select's validation function to its onchange event? http://meteorpad.com/pad/t5LdBwn6YiXjCFwko/UserAccounts%20Validation |
@cunneen, sorry for the late reply. I had a look at the problem and it's a mixture of things:
<template name="selectSchool">
<label for="at-field-school">{{displayName}}</label>
<select id="at-field-{{_id}}" name="at-field-{{_id}}">
<option value="select">Please select</option>
<option value="one">School One</option>
<option value="two">School Two</option>
</select>
</template> then you also need to enable validation setting to AccountsTemplates.addFields([
/* ... */
{
_id: 'school', //Add a school select to the form
type: 'select',
displayName: 'Select a school',
select: [],
template: "selectSchool",
errStr: 'Select a School',
func: function(value){
if (Meteor.isClient) {
console.log("Validating school..." + value);
this.setSuccess();
// or this.setError(userExists);
this.setValidating(false);
return;
}
},
negativeValidation: true,
},
/* ... */
]); hopefully this should be enough to solve your issue! |
Hi,
I am trying to assign dynamic values to select option as below:
AccountsTemplates.addFields([
{
_id: 'customField',
type: 'select',
displayName: 'Custom Field',
select: custFunct(),
}
]);
custFunct() is a function i have defined as below
var custFunct = function() {
var jsonArr = [];
var jsonObj = {};
jsonObj.text = "Cust1";
jsonObj.value = "cust1";
jsonArr.push(jsonObj);
};
Post this I am able to see the dropdown getting populated with Cust1 and Cust2 correctly
Now, i have to get these values from one of my collection which is not working as below
var custFunct = function() {
return CustCollection.find().fetch(); // this line gives error that CustCollection is not defined.
};
Kindly suggest how to proceed.
The text was updated successfully, but these errors were encountered: