Developer forum

Forum » Development » Don't write out empty fields

Don't write out empty fields


Reply

I have some fields from the Shop module that has to be checked if they are empty (and if they are go to the next field) before the write out on the page. I have been told that this can be done with some JavaScript and hope that some of you can be able to help out here..


 


Best


 


/Karsten


Replies

 
Reply
Hi



Well, you use Shop module, you created several custom product fields. Now you want to display product on frontend using "Product Catalog" module and hide empty custom fields, yes?

This is changed ShopCustomFieldsList.html template below for your purposes, it works both in IE and FF:

----------------------------------------



   

       

   

       

Custom felter




----------------------------------------

Vitaly.
 
Reply

Hi


 


Thanks for you reply, my file looks like this:


 










 

 



 



 
Tilknyttet:


 

E-mail: 


 
Tlf dir: 


 
Mobil: 


 
Adresse:  









 


                Uddannelse:



  Interesseområder:



  Erfaringsbaggrund:



 


 


  Websider:



  Team:


 


       


        Publikationer:


      




 


Could you maybe phow how the !--@Text06-- is hidden ih empty?

 
Reply
Try to place your code inside some span with id attribute, e.g.

. In you JS procedure get this span element:

document.getElementById('Text06'), check is it empty and set display style to none if it is empty (see my sample code above).
 
Reply
vme wrote:

Try to place your code inside some span with id attribute, e.g.



. In you JS procedure get this span element:



document.getElementById('Text06'), check is it empty and set display style to none if it is empty (see my sample code above).



Ahh, Im not the big JS developer, can you please explain more?


 


PS: Thanks for all the help :o)

 
Reply
Basically, you should find your row and value elements, check value's length and hide row if value is empty:



var span = row.getElementById("Text06");

var div = row.getElementById("pubEmp");

if (span && div)

{

    var value = span.innerHTML;

    if (value.length == 0)

        div.style.display = 'none';

}
 
Reply

Should'nt this work??:




 




 






  Websider





  





  







 





 




 






strInit = '';

if(strInit.length > 0){

 document.getElementById('employeeImg').src = 'Files/billeder/medarb/'+ strInit +'.jpg';

}


var fieldsArr = new Array('Web')


for(i = 0; i < fieldsArr.length; i++){

  if(document.getElementById('div'+ fieldsArr[i]) && document.getElementById('txt'+ fieldsArr[i])){

    //Fields exist

    if(document.getElementById('txt'+ fieldsArr[i]).innerHTML.length <= 0){

      document.getElementById('div'+ fieldsArr[i]).style.display = 'none';

      document.getElementById('txt'+ fieldsArr[i]).style.display = 'none';

    }

  }

}


 
Reply
I don't see your template's markup, but JS code looks at least supposed to the thing you want.
 
Reply

Great, I have this working now, but I need to check if there is a picture in the folder or else it should write out "x.gif" so some kinde of check on the picture - right now it writes out a red cross.


 


It is now checking if there is a  and they are always there, so I need some kind of check on, is there a picture in the folder "files/Filer/Employees/" and if not, then write out x.gif


 


Hopefully you can help...


 




 
Reply
You can use onerror event handler for tag. Something like this one:








 

You must be logged in to post in the forum