0

while clicking the button i want to check the array field value is null or not

code

function renderblock(){
         alert('jjj');
         var result = '{!filterArray}';
           alert(result );
  } 

Alert result ::filterArray values :

[filterField:[label=AccountName, searchFieldName=FULL_NAME, searchValue=]], [filterField:[label=City, searchFieldName=PRIM_CITY, searchValue=test]], [filterField:[label=Country, searchFieldName=PRIM_COUNTRY_NM, searchValue=]], [filterField:[label=Street Address, searchFieldName=PRIM_ADDR_LN_1, searchValue=]], [filterField:[label=State/Province, searchFieldName=PRIM_STATE, searchValue=]], [filterField:[label=Zip/PostalCode, searchFieldName=PRIM_POSTAL_CD, searchValue=]]

In the controller my array value is :

[filterField:[label=AccountName, searchFieldName=FULL_NAME, searchValue=]], [filterField:[label=City, searchFieldName=PRIM_CITY, searchValue=test]], [filterField:[label=Country, searchFieldName=PRIM_COUNTRY_NM, searchValue=]], [filterField:[label=Street Address, searchFieldName=PRIM_ADDR_LN_1, searchValue=]], [filterField:[label=State/Province, searchFieldName=PRIM_STATE, searchValue=test]], [filterField:[label=Zip/PostalCode, searchFieldName=PRIM_POSTAL_CD, searchValue=uma]]

Means am having value for "serachfield" But when i click the button javascript is called first and giving empty values.how to overcome this ?

In this array i want to check atleast one searchvalue attribute is filled or not ..Please help

2

I suggest using JSON serialize string in apex

public String getJsonArray()
{
  return JSON.serialize(filterArray);
}

and again in VF page use

<script>

    var arraylist = JSON.parse('{!JsonArray}');
    for(var i = 0; i<arraylist.length; i++)
    {
      console.log(arraylist[i]); //check here field null or not
    }

</script>
  • could you please review my question again.I just edited now – sonu Apr 27 '17 at 11:49
  • when you click on button and call the apex method. you have rerender in VF page to get the updated values @ramu – Ratan Paul Apr 27 '17 at 12:19

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.