Two page_selectors on a single form

Permalink
I had the need for two page selectors in a single form, but the last one was always the one that gets updated after the selection. The first callback seems to get redefined before the form is rendered. A workaround (w/o touching core files) is to specify your own callback for each call to selectPage() and then store the resulting ccm_selectSitemapNode function in your own var. Hopefully an update to C5 in the future will save having to do this and will break the code below:

<?php
   $ps = Loader::helper('form/page_selector');
   echo $form->label('myID1', t('Choose page #1'));
   print $ps->selectPage('myID1',($myID1 > 1 ? $myID1 : 1), 'myFunction1');
?>
<script type="text/javascript">
APP = APP ? APP : {};
// save the callback before the second selectPage() call redefines it
APP.ccm_selectSitemapNode1 = ccm_selectSitemapNode;
</script>
<?php
   echo $form->label('myID2',t('Choose page #2'));
   print $ps->selectPage('myID2',($myID2 > 1 ? $myID2 : 1), 'myFunction2');
?>
<script type="text/javascript">

 
hutman replied on at Permalink Reply
hutman
What type of form are you using this on and what version of c5?

I have used this on a block form and a dashboard page with no need for extra javascript within the page. As long as the ID of the elements are different it should update the correct one.
dennismoore replied on at Permalink Reply
It was an add/edit form for a custom block in C5 v.5.6.3.1
hutman replied on at Permalink Reply 1 Attachment
hutman
I created a quick package that has a block in it that has 2 page selectors, they stay separate and seem to work fine with 5.6.3.1 which is the newest release.

I hope that this can help you, your code looks like it is right though.
dennismoore replied on at Permalink Reply
Your example works but you're not trying to do anything with js. Change your edit.php to below and it stops working:

<?php
defined('C5_EXECUTE') or die("Access Denied.");
$pageSelector = Loader::helper('form/page_selector');
?>     
<div class="ccm-ui"> 
     <div class="control-group">
     <label class="control-label">Page 1</label>
     <div class="controls">
               <?php echo $pageSelector->selectPage('linkCID', $linkCID, 'ccm_selectSitemapNode'); ?>
     </div>
     </div>
     <div class="control-group">
     <label class="control-label">Page 2</label>
     <div class="controls">
               <?php echo $pageSelector->selectPage('testCID', $testCID, 'myfn1'); ?>
hutman replied on at Permalink Reply
hutman
I see what you are trying to do, it's not that the PageSelector isn't working, it's that the javascript callback isn't working. After looking at the core I don't know if there is any way to change that, but I did find that you could do something like below so that you can execute a call on the correct page selector.

<?php
defined('C5_EXECUTE') or die("Access Denied.");
$pageSelector = Loader::helper('form/page_selector');
?>     
<div class="ccm-ui"> 
     <div class="control-group">
     <label class="control-label">Page 1</label>
     <div class="controls" id="linkCID">
               <?php echo $pageSelector->selectPage('linkCID', $linkCID, 'pageSelectFunction'); ?>
     </div>
     </div>
     <div class="control-group">
     <label class="control-label">Page 2</label>
     <div class="controls" id="testCID">
               <?php echo $pageSelector->selectPage('testCID', $testCID, 'pageSelectFunction'); ?>