Problems, need help? Have a tip or advice? Post it here.
14 posts Page 1 of 2
Hi

A weird little one here, because this really ought to be very simple but it is not working, as far as I can tell...

I have a clonable page "foreign-requirements.php" with these editables:

Code: Select all
<cms:template title='Foreign Country Requirements' clonable='1' icon='globe'  order='6'>
<cms:editable name='country_code' label='Two-Letter Country Code' desc='Please be sure to use the ISO 3166 Country Code' type="text" maxlength="2" searchable="0" required="1" validator='exact_len=2 | alpha' validator_msg='exact_len=The Country Code field must be exactly 2 letters | alpha=The Country Code must only use the letters A-Z' />
<cms:editable name='continent' label='Continent' type='dropdown' desc='Select one of these' opt_values='Please Select=- | Africa=africa | Asia=asia | Europe=europe | North America=north_america | South America=south_america | Oceania=oceania' required="1" validator_msg='required=You must select a Continent!' />
<cms:editable name='patent_doc' label='Upload the Patent Requirements pdf document here' desc='Leave blank if document does not exist' type="file" />
<cms:editable name='tm_doc' label='Upload the Trade Mark Requirements pdf document here' desc='Leave blank if document does not exist' type="file" />
<cms:editable name='design_doc' label='Upload the Design Requirements pdf document here' desc='Leave blank if document does not exist' type="file" />
<cms:config_form_view>
    <cms:field 'k_page_title' label='Country Name' />
</cms:config_form_view>
</cms:template>


I wish to display the countries in a table - so for the code for displaying all cloned pages I have this:

Code: Select all
<thead class="thead-dark">
    <tr>
        <th colspan="3" style="text-align:left; white-space: nowrap; border-right: 1px solid;" scope="colgroup">Country</th>
        <th style="text-align:center; white-space: nowrap;" scope="col">Patents</th>
        <th style="text-align:center; white-space: nowrap;" scope="col">Trade Marks</th>
        <th style="text-align:center; white-space: nowrap;" scope="col">Designs</th>
    </tr>
</thead>
<tbody>
<cms:pages orderby='country_code' order='asc' >
    <tr>
        <th class="country_code" style="text-align:center; white-space: nowrap;" scope="row"><a href="https://www.wipo.int/directory/en/details.jsp?country_code=<cms:show country_code />" data-toggle="tooltip" data-placement="right" title="See this country on WIPO"><cms:show country_code /></a></th>
        <td class="country_flag" style="text-align:center; white-space: nowrap;"><img src="https://flagcdn.com/h20/<cms:show country_code />.png"></td>
        <td class="country_name" style="text-align:left; white-space: nowrap; border-right: 1px solid;"><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></td>
        <td class="patent_requirements" style="text-align:center; white-space: nowrap;"><cms:if patent_doc ><a href="<cms:show patent_doc />" target="_blank" data-toggle="tooltip" data-placement="right" title="See this factsheet"><i class="fas fa-check-circle"></i></a><cms:else /><i class="far fa-times-circle"></i></cms:if></td>
        <td class="tm_requirements" style="text-align:center; white-space: nowrap;"><cms:if tm_doc ><a href="<cms:show tm_doc />" target="_blank" data-toggle="tooltip" data-placement="right" title="See this factsheet"><i class="fas fa-check-circle"></i></a><cms:else /><i class="far fa-times-circle"></i></cms:if></td>
        <td class="design_requirements" style="text-align:center; white-space: nowrap;"><cms:if design_doc ><a href="<cms:show design_doc />" target="_blank" data-toggle="tooltip" data-placement="right" title="See this factsheet"><i class="fas fa-check-circle"></i></a><cms:else /><i class="far fa-times-circle"></i></cms:if></td>
    </tr>
</cms:pages>
</tbody>


This code works perfectly for generating a table of the pages, all of the features work well, except for the orderby. I currently (as a test) have pages with country_code US and CA and I cannot get the rows to display in alphabetical order - surely the 'orderby' ought to fetch the pages based on the two letter text field country_code. I have tried 'asc' and 'desc' and it makes no difference.

Please help!? Thank you
Hi helpful folk,

I still can't get this to work, and I fear I'm making a silly mistake. Is there any reason "orderby" that custom text field wouldn't order the rows alphabetically? I've gone over it, and in my head it should work...

Couch fetches pages, in order, according to two-letter code
Each page it fetches, it spits out <tr> content </tr>
Therefore I should end up with a series of table rows in alphabetical order according to the custom field 'country_code', no?
Hi,

I tried your code out and it is working just fine for me.
Code: Select all
<cms:pages orderby='country_code' order='desc'>
    <h3><cms:show country_code /></h3>
</cms:pages>

With three sample pages with country_codes of IN, CA and US,
using 'asc' I get CA, IN, US and with 'desc' it becomes US, IN, CA.
Hi KK!

Thank you for looking into this! :D Did you set the editable with the same constraints as I did?

I simply cannot get it to work. I did a test for Germany (DE), Estonia (EE), France (FR), Canada (CA) and Australia (AU) - when I change the code to:

Code: Select all
<cms:pages orderby='continent' order='asc' >
    <cms:set country_code_lc="<cms:php>echo(strtolower(<cms:show country_code />));</cms:php>" />
    <tr>
        <h1><cms:show k_page_title /></h1>
    </tr>
</cms:pages>

I get
    Germany
    Estonia
    France
    Canada
    Australia

which is correct, since it is Europe, North America, Oceania. Changing to descending changes this to reverse order (with countries still in the same order within their respective groups).

But when I switch the code to:

Code: Select all
<cms:pages orderby='country_code' order='asc' >
    <cms:set country_code_lc="<cms:php>echo(strtolower(<cms:show country_code />));</cms:php>" />
    <tr>
        <h1><cms:show k_page_title /></h1>
    </tr>
</cms:pages>

I get them in the order I created them, and changing asc to desc makes no change.

This is driving me insane, because there must just be something slightly off, but clearly the code works fine otherwise so where is the error?!? :oops:
Did you set the editable with the same constraints as I did?

Yes, I copy/pasted your definition.

What does the simplified code (that worked for me) output for you?
Code: Select all
<cms:pages orderby='country_code' order='desc'>
    <h3><cms:show country_code /></h3>
</cms:pages>
Hi KK,

Yes - I did - a copy/paste of your output code for my test pages results in this:

Image

I have done some experimenting, and can confirm there is some kind of bug, but I can only help with identifying where since I cannot for the life of me understand what is going on behind the scenes!

I tried uploading a second version of the same template (with -test added to both .php filename and template title) and it replicated the problem exactly. So then I started tweaking bits of code within this 'test' page. I could not get it to work.

I then tried uploading a new version of this test page (with -test-again added to filename and template title) and it worked all of a sudden. The only change I made, as far as I could tell, was that I deleted the 'form view config' that was renaming 'Title' to 'Country Name' i.e. I deleted
Code: Select all
    <cms:config_form_view>
    <cms:field 'k_page_title' label='Country Name' />
</cms:config_form_view>


I tested it, and orderby country code was working - so (having already created multiple pages that were succesfully ordered) I reintroduced that piece of code to the live 'test-again' page and it succesfully renamed the 'Title' field in the editor view AND preserved the orderby functionality (I was able to switch between asc and desc and it was fine).

So - I went into the original page code, deleted that line of code, but no matter which pages or how many times I tried hard refreshing, Couch absolutely refused to forget that 'Title' was renamed 'Country Name' and continued to refuse to orderby country_code.

So I deleted all 3 of these templates, hard refreshed, checked they were gone, and then reuploaded the original page minus that piece of code. This time, it showed 'Title' instead of 'Country Name'. I threw a handful of test pages in, and again it refused to orderby country_code.

Offline I renamed the original .php file, gave it a new template title, and uploaded it. Got it up and running, threw some pages in, and it was happy to orderby country_code. I then reintroduced the line of code and the editor show 'Country Name' instead of title, and is still happy to orderby country_code... So - there is a ghost in the machine... something is hanging around from an earlier iteration of the page, which means (it seems) that the original filename (foreign-requirements.php) is now haunted, and cannot function properly, even after deleting and reuploading.

So, I now must stick with using this renamed file (no biggy, just means I cannot have the URL I originally wished to have - rather than /foreign-requirements.php I am now using /foreigns.php) and it works.

However, I did not want to leave it somewhat mysterious like this - so I did one last check. I took this now fully functioning 'foreigns.php' which includes the problematic line of code, and offline I renamed it foreigns-check.php (a previously unused URL / filename) and uploaded it. Sure enough, once I threw some pages in, it could not orderby country_code.

So - my conclusion - there is some kind of bug with the form config code, which persists even after deleting a template, and which causes problems for orderby. The really confusing part is that in my code it prevented orderby='country_code' but not orderby='continent'

Good luck puzzling this one out!! :shock:
Apologies - a further update.

I have just added a new page after having reintroduced that line of code, and where before I had:

    AU
    CN
    DE
    ZA

I introduced VN and got

    AU
    VN
    CN
    DE
    ZA

The page creation order is

    VN
    AU
    DE
    ZA
    CN

So - it seems that line of code breaks orderby='country_code' going forward from when it was introduced - the pages created prior to introducing the form config code are still able to be ordered by country_code - however, switching the live code from asc to desc results in:

    ZA
    DE
    CN
    AU
    VN

So it is like the config view breaks the country_code field in each page created, because those created prior to introducing the code are still available for orderby :?:
Can you zip the files and a copy of database?
Unfortunately not - it's held under lock and key by the IT team (and for good reason - the webpages are hosting a lot of confidential information, viewable only to those who work for our firm).

I am happy to dump the whole template code for you though, for the problematic template. I have replaced all the cms:embed sections with the code they point to - there is nothing else (other than a stylesheet) that the template relies upon that would prevent you from replicating the template and problem.

To see exactly how it seems to break, upload the page without the problem code (config_form_view) and create templated out pages, see how they are happy to orderby. Then reintroduce the problem code, and see how all subsequently made pages refuse to take part in the orderby.

Attachments

Pardon my french, but #!%$?? Template says searchable="0" is set for editable 'country_code'. It tells Couch it should never be searchable, i.e. filters and orders also won't work (why would they work on something that can't be found?). Reconsider this setting and resave affected pages (new ones will be ok).
14 posts Page 1 of 2
cron