def field_selector_callback():
    """Return JS callback for field selection checkboxes

    Returns
    -------
    code : :obj:`str`
    """
    code = """
        /*bsize: total number of items in a batch
         bsel: the batch selector group buttons
         csel: corr selector group buttons
         nants: Number of antennas
         ncorrs: number of available correlations
         nfields: number of available fields
         nbatches: total number of available batches
         ax: List containing glyphs for all antennas, fields and  correlations
         count: keeping a cumulative sum of the traverse number
        */
        let count = 0;
        let new_bsize;
        for (let sp=0; sp<nspws; sp++){
            for (let f=0; f<nfields; f++){
                for (let c=0; c<ncorrs; c++){
                    //re-initialise new batch size
                    new_bsize = bsize;
                    for(let n=0; n<nbatches; n++){
                        // Reduce new batch size to the size of the last batch
                        if (n == nbatches-1 && nants!=bsize){
                            new_bsize = nants % bsize;
                        }
                        for(let b=0; b<new_bsize; b++){
                            if (cb_obj.active.includes(f) && csel.active.includes(c) &&
                                ssel.active.includes(sp)){
                                ax[count].visible = true;
                                }
                            else{
                                ax[count].visible = false;
                            }
                            count = count + 1;
                        }
                    }
                }
            }
        }
       """
    return code
