1

I am using Knockback.js. I am a newbie to this whole javascript and html. I am trying to poplulate the hidden field in the function addFolder, But it always showing null. This is the following javascript code(viewmodel).

GroupsView = LS.ViewModel.extend({
initialize : function(options) {
if(typeof options != 'undefined'){
        this.projectskey = options.projectskey;
        this.folderkey = options.folderkey;
    }
    this.options = options;
    this._this = this;
    this.c = new GroupsCollection(null, options);
    this.c.fetch({
        add : true
    });
    this.groups = kb.collectionObservable(this.c);
},
fetch : function() {
    $('#loadingAnim').show();
    this.groups.collection().fetch({
        update : true,
        add : true
    });
},
addFolder: function(vm, event){
    event.preventDefault();

    $("#plgGroupsGetContents").val(vm.projectskey); 
    $("#plgGroupsGetContents1").val(vm.folderkey);
    vm.c.addFolder();
    $('#dialogAddFolders').modal('hide');
}

});

and this is the following html code

 <form action="/groups/createfolder" id="addFoldersForm" data-bind="event: {submit: $root.addFolder.bind() }">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel" data-bind="text: LANG.getText('plgGroupAddFolder')"></h4>
        </div>
        <div class="modal-body">
            <input type="hidden" name="projectskey" id="plgGroupsGetContents" value="">
            <input type="hidden" name="rootfolder" id="plgGroupsGetContents1" value="">
            <span data-bind="text: LANG.getText('plgGroupFolderName')"/><input type="text" data-bind="attr: {placeholder: LANG.getText('plgNameDefaultText')}" required title="Folder name" name="foldername" data-icon="U"><br>       
         </div>
        <div class="modal-footer">
            <button data-bind="text: LANG.getText('plgGroupAbort')" type="button" class="btn btn-default" data-dismiss="modal"></button>
            <button data-bind="text: LANG.getText('plgGroupAddFolderOKBtn')" class="btn btn-primary"></button>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

Can you please suggest me some ideas. Thanks in advance

Acjb
  • 505
  • 1
  • 6
  • 21
  • in Jquery using Javascript? You need to change title. – Farhad Jabiyev Jul 27 '14 at 14:05
  • `console.log(vm.projectskey, vm.folderskey);` after your preventDefault and tell us what is in there. As `$('...').val('new');` is right. – thepratt Jul 27 '14 at 14:45
  • it shows null null for vm.projectskey and vm.folderkey. @nuc – Acjb Jul 27 '14 at 15:00
  • That's your issue then. The data being brought in is empty. Try and work backwards from that. – thepratt Jul 27 '14 at 16:38
  • I hav already mentioned in my question that it shows null. But i dont know exactly why it is null. Can you suggest me some ideas? I m new to this javascript. – Acjb Jul 27 '14 at 17:25

0 Answers0