Search code examples
javascriptjquerymeteorsemantic-uiiron-router

How to set default session and dropdown values in meteor?


I have a collection which store default values according to the logged in user. I have a setting menu where default can be set for the application by the user. How can we set the dropdown of that setting menu to the default value set previously by user every time and how can we set the default session value. I'm using semantic UI and isron router, I'm trying to get the default values from the collection in .onRendered(), but the output will be Values:

Template.header.onRendered (function(){
    var defaultSettingValues=defaultSetting.find().fetch()
    console.log ("Values: "+defaultSettingValues);
});

The dropdown in settng menu:

<div class="ui selection dropdown button" id="defaultDrop" tabindex="0">
    <input type="hidden" name="filter">
    <div class="default text">Select from here</div>
    <i class="right floated dropdown icon"></i>
    <div class="menu" tabindex="-1">            
        <div class="item" data-value="objId1">abc</div>                                     
        <div class="item" data-value="objId2">def</div>                                     
        <div class="item" data-value="objId3">hij</div>                                     
    </div>
</div>

I'm trying to get the default setting values from collections and then set the session and set the default dropdown.
How can i solve this? or is there any alternate way in which i can achieve this?


Solution

  • Ok so you can set default value of your dropdown with the following code :

    Template.header.onRendered (function(){
        // Care because it returns an array, and you just need the default value
        var defaultSettingValues=defaultSetting.find().fetch(); 
    
        // Supposing the defaultSettingValues is equals to 'objId1'
        $('#defaultDrop').dropdown('set selected', defaultSettingValues);
    });
    

    You need to find a way to get your value from what's returning your collection.