1

I'm using jQuery to create a listview and a filter. If the user clicks an item I want the filter to set the text to the item clicked and hide the list. But not permanently! The list needs to come back if the user changes the filter text.

Here is what I have:

    $(document).ready(function () {

        jQuery.support.cors = true;
        $("#groupSelectList").listview({
            filter: true,
            filterPlaceholder: '',
            icon: false
        });

        $('#groupSelectList').children('li').on('click', function () {
            $('#groupName').val($(this).text());
            $("input[data-type='search']").val($(this).text())
            //$("#groupSelectList").listview("refresh");//this refresh doesn't appear to do anything.
            $("#groupSelectList").listview().hide()//hide works, but the list won't come back if the user changes the input text.
        });
    });

...

The widget on this page is an example of the control I'm using: http://view.jquerymobile.com/master/demos/

1
  • I have two Jquery Mobile List view on same page and this $("input[data-type='search']").val($(this).text()), assigns value to both text search. Is there any way to define id to "input[data-type='search'" Commented May 7, 2015 at 13:20

2 Answers 2

1

I figured out how to make this happen. In case anyone is interested, to get the jQuery mobile listview control to disappear on click and then re-appear on change I bound a temporary keyup event to the search box. My code now looks like this:

    var groupSelectHandler = function () {
        $("#groupSelectList").listview().show()
        $("#groupSelectList").listview("refresh");
        $("input[data-type='search']").unbind('keyup', groupSelectHandler);
    }

    $(document).ready(function () {
        $("#groupSelectList").listview({
            filter: true,
            filterPlaceholder: ''

        });

        $('#groupSelectList').children('li').on('click', function () {
            $('#groupName').val($(this).text());
            $("input[data-type='search']").val($(this).text());
            $("#groupSelectList").listview().hide();
            $("input[data-type='search']").bind('keyup', groupSelectHandler);
        });
    });

You can see in this example that when click is fired groupSelectHandler is bound to keyup. When keyup fires it shows the list and removes the keyup event.

Sign up to request clarification or add additional context in comments.

Comments

1

A possible, much simpler solution might be:

$( document ).on( "pageinit", "#myPage", function() {
    $('#groupName').val($(this).text());
        $("input[data-type='search']").val($(this).text());;
    $('#groupSelectList li').each(function (index) {
        $(this).addClass("ui-screen-hidden");
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.