I've been struggling to find a solution to this issue, so I'm reaching out to the stackOverflow community for help. While it may seem like a common problem, the example I'm dealing with has proven to be unique in my research.
Within a meteor template, I have a select dropdown that is structured as follows:
{{#each phoneNumber}}
<li>
<input id="{{this._id}}" type="text" name="phoneNumberItem" placeholder="Phone number here" value="{{number}}">
<select id="{{this._id}}" name="type">
<!-- go through collection and see which is selected there, mark it as selected here so they match -->
<option selected="{{selectedOrNot}}" name="selection">Work</option>
<option selected="{{selectedOrNot}}" name="selection">Home</option>
<option selected="{{selectedOrNot}}" name="selection">Mobile</option>
<option selected="{{selectedOrNot}}" name="selection">Office</option>
<option selected="{{selectedOrNot}}" name="selection">Fax</option>
<option selected="{{selectedOrNot}}" name="selection">Other</option>
</select>
<input id="{{this._id}}" type="button" class="remove" value="X">
</li>
{{/each}}
In the helper function 'selectedOrNot', I am attempting to determine which option should be selected based on the data retrieved from the collection:
Template.addPhoneNumber.helpers({
'phoneNumber': function() {
return newOrgPhoneNumbers.find();
},
'selectedOrNot': function(event){
var collectionType = newOrgPhoneNumbers.findOne();
var typeFormName = $('[name="selection"]').val();
if(collectionType.type === typeFormName){
console.log ('selected!');
return 'selected';
}
}
});
The objective is to display the correct selection based on the 'type' field in the 'newOrgPhoneNumbers' collection. However, I have identified an issue where 'typeFormName' always defaults to "Work", resulting in incorrect selections.
I have spent considerable time trying to resolve this independently, but it seems I require additional guidance. Any assistance you can provide would be greatly appreciated. Thank you. - Rob