Javascript list.js to this php code

1.3k views Asked by At

I love this script list.js from www.listjs.com. It seems to be the perfect fit for searching and filtering the output of a php file below, but I just can get it to work, I only need to add 7 or so lines of code but its not working. Can anyone tell me how come? Thanks

The code that I added is highlighted

<?php
defined('_JEXEC') or die();
?>
**<script type="text/javascript" src="list.js"></script>**
<form action="<?php echo CRoute::getURI(); ?>" method="post" id="jomsForm" name="jomsForm" class="community-form-validate">
<div class="jsProfileType" **id="jsProfileType"**>
    **<input class="search" placeholder="Search" />
        <button class="sort" data-sort="label">
            Sort
        </button>**
    <ul class="unstyled">
    <?php
        foreach($profileTypes as $profile)
        {
    ?>
        <li class="space-12">

            <label for="profile-<?php echo $profile->id;?>" class="radio">
                <input id="profile-<?php echo $profile->id;?>" type="radio" value="<?php echo $profile->id;?>" name="profileType" <?php echo $default == $profile->id ? ' disabled CHECKED' :'';?> />
              <strong class="bold"><?php echo $profile->name;?></strong>
            </label>
            <?php if( $profile->approvals ){?>
                <span class="help-block"><?php echo JText::_('COM_COMMUNITY_REQUIRE_APPROVAL');?></span>
            <?php } ?>

            <span class="help-block">
                <?php 
                    $profile->description = JHTML::_('content.prepare',$profile->description);
                    echo $profile->description;?>
            </span>

            <?php if( $default == $profile->id ){?>
                    <em><?php echo JText::_('COM_COMMUNITY_ALREADY_USING_THIS_PROFILE_TYPE');?></em>
            <?php } ?>



        </li>
    <?php
        }
    ?>
    </ul>
</div>
<?php if( (count($profileTypes) == 1 && $profileTypes[0]->id != $default) || count($profileTypes) > 1 ){?>
<div style="margin-top: 5px;">
    <?php if( $showNotice ){ ?>
    <span style="color: red;font-weight:700;"><?php echo JText::_('COM_COMMUNITY_NOTE');?>:</span>
    <span><?php echo $message;?></span>
    <?php } ?>
</div>
**<script>
var options = {
    list: "space-12"
};
var userList = new List('jsProfileType', options);
</script>**
<table class="ccontentTable paramlist" cellspacing="1" cellpadding="0">
  <tbody>
    <tr>
        <td class="paramlist_key" style="text-align:left">
            <div id="cwin-wait" style="display:none;"></div>
            <input class="btn btn-primary validateSubmit" type="submit" id="btnSubmit" value="<?php echo JText::_('COM_COMMUNITY_NEXT'); ?>" name="submit">
        </td>
        <td class="paramlist_value">

        </td>
    </tr>
</tbody>
</table>
<?php } ?>
<input type="hidden" name="id" value="0" />
<input type="hidden" name="gid" value="0" />
<input type="hidden" id="authenticate" name="authenticate" value="0" />
<input type="hidden" id="authkey" name="authkey" value="" />
</form>
1

There are 1 answers

1
THelper On

I don't know PHP, but I have seen this error before when I used list.js in my own project. It turned out I didn't define things properly.

You did set up a div with a proper id, but you seem to be missing a 'list' class. Try changing

<ul class="unstyled">

to

<ul class="list">

Second, I don't think that 'list' is a supported keyword in options (at least not in the most recent list.js version). Try changing your options definition to

var options = {
    valueNames: [ 'space-12' ]
};

Third, if you want search to work change

<button class="sort" data-sort="label">

to

<button class="sort" data-sort="space-12">