In this article, we will show you how to set a mandatory search filter inside the userview. In this sample case, we will use the Title as the mandatory filter.

Before entering search filter:


After entering the search filter:


To start, choose the desired filters for the datalist builder and make sure to identify the URL Request Parameter of the mandatory filter, which in this case is Title.

Now that we have set up the app, we can now proceed to set the Javascript for the mandatory filter.

  1. Go to the UI Builder
  2. Click on the CRUD that you want to add the restriction to
  3. Click on the UI (List) tab
  4. Add the Javascript to the custom footer
Javascript
<script>
    $(document).ready(function(){
        // Filter form
        filters = $("#filters_test");
        // Filter ID
        title = $("#d-49700-fn_title");
        // Need to give a small delay to allow the page to fully load
        setTimeout(function(){
            // Submit button
            btn = filters.find(".waves-button-input")[0];
            btn.onclick = function(event){
                if(title.val() == ''){
                    alert("Title must be designated");
                    event.preventDefault();
                }      
            };
        },250); // Increase this value to >1000 if script doesnt run properly
    })
</script>
  • No labels