facebook

Deselecting SelectListItem with a button? CLOSED

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #341379 Reply

    paulD
    Member

    Hi everyone,

    I’m trying to get this to work, but as always its not going to plan 🙂

    I want to be able to push a button which will deselect the selected items of a list. I’ve been trying this from the list widgets snippets but have added the selected false bit instead of the log of the val.

    $('select[name="list1"] :selected').each(
       function(i, selected) {
            
            $(selected).prop("selected", false);
            
       }
      )

    It doesn’t work you won’t be surprised to know…. Javascript hates me… Anyway I know the array works as i can log the selected items values. Its the prop bit which doesn’t fire, it doesn’t fire an error in the debugger, just doesn’t fire.

    Thanks for any help

    Paul

    Attachments:
    You must be logged in to view attached files.
    #341382 Reply

    Stu Wade
    Member

    Hi Paul,

    Here’s the solution, from Octavio I think …

    $(‘#m1-page-selectListItem’+j).removeClass(m1Design.css(‘selected’));

    Where j runs through the list, does no harm if item is unselected.

    I had exactly the same problem…

    #341394 Reply

    Hi Paul,

    Please try the snippet of code I shared in this thread: http://www.genuitec.com/support-genuitec/viewtopic.php?p=8909#p8909

    Let me know if you need further assistance.

    #341395 Reply

    Paul_paul
    Participant

    Cincy Planet shared this code with me it works fine.

    $('.m1-selection-list > li').each(function (i) {
      $(this).removeClass(m1Design.css("selected"));
    });
    phoneui.preprocessDOM();
    #341416 Reply

    paulD
    Member

    Great stuff guys. Works a treat! Thanks for your input

    Just in case anyone else in the future needs to do this –

    For deselecting a specific list in the project just change ‘m1-unselect-list1’; to your list ID

    var selListId = 'm1-unselect-list1';
    var listName = 'list1';
    
    var itemToSelect = $('select[name='+listName+'] :selected').prop("selected", false); 
    
    var selId = $('#' + selListId + '> li').each(
    function (i) {
      $(this)[i == itemToSelect ? 'addClass' : 'removeClass'](m1Design.css("selected"));
    });
    
    // This line updates hidden select, for the case the whole 
    // design will be used as a form
    phoneui.preprocessDOM('#' + selListId);

    for every list in the project its a little simpler –

    $('.m1-selection-list > li').each(function (i) {
      $(this).removeClass(m1Design.css("selected"));
    });
    phoneui.preprocessDOM();

    this topic is now closed!

    #341425 Reply

    Hi Paul,

    I am glad that the snippet code worked for you. Closing thread.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Deselecting SelectListItem with a button? CLOSED

You must be logged in to post in the forum log in