0

I have a visualforce page, in which autocomplete functionality implemented for a field using Jquery. While displaying the results in the suggestions, I would like to filter the record based on a check box.

Though i have given appropriate filters in the queries, but couldn't control the records coming in the suggestions, i mean all records are coming under suggestions.

3
  • How are you getting the values? Is it through RemoteAction? – Saroj Bera Mar 10 '17 at 9:13
  • I am forming an url, that contains the conditions along with checkbox__c = true..in return i am getting the false records as well. $('[id="{!compId}"]').addClass('ui-autocomplete-loading'); //prompt('',sourcePage+'&key='+txtVal.val()); $element.data('jqXHR',$.ajax({ url: sourcePage+urlPrms, dataType: "json", data: { } in urlprms, i am sending my conditions – venky Mar 10 '17 at 9:21
  • You should use JavaScript Remoting (as also suggested by @SarojBera) or Visualforce remote objects! – Raul Mar 13 '17 at 8:26
0

Without taking a look at the code, I can only assume you're casting the checkbox value directly on the jquery, something like

var filter = "{!myCheckbox}";

For this to work, you need to reRender that part of the code when you change the checkbox:

<apex:inputCheckbox value="{!myCheckbox} id="myCheckbox">
    <apex:actionSupport event="onchange" reRender="myJavascriptPanel"/>
</apex:inputCheckbox>

Alternatively, you need to find te value of the checkbox on run time with jQuery:

function autoComplete(){
    var filter = $('[id$="myCheckbox"]').prop("checked");
    //populate list of values and show belo input
}
3
  • Hi Fernado, I am executing a url that sends request and gets response..while sending request i am passing checkbox__c = ture...but in the response i am getting false records aswell. – venky Mar 10 '17 at 9:10
  • Then the problem is with the service that provides the records. If you have access to it, take a look at the code an check if the parameter name is correct and that the parameter is being used. If you don't, contact the provider – Fernando Gavinho Mar 10 '17 at 9:29
  • Hi Fernando, updated the question with code..Could you please help. – venky Mar 13 '17 at 6:29
0

First, you should try to fix the issue at the source. As a workaround, you can filter the result inside the success function of the Ajax call. Create an empty array and push the only values you want to show in the suggestion box from the actual response.

var filtered = [];
$.ajax({
    method: 'GET',
    dataType: 'jsonp',
    jsonpCallback: 'jsonCallback',
    url: suggestURL
})
.success(function(data){
    $.each( data[1], function( key, value ) {
        if(value=='hello'){
            filtered.push(value);
        }
    });
    response(filtered);
});

Check this fiddle link for a working demo.

1
  • Hi Saroj, Here is my code..I couldn't able to incorporate the changes you have mentioned above. Could you please help..updated the question, please look for the code – venky Mar 13 '17 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.