Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Hey KK,

I need to search repeatable regions. The work around I have used involves the use of the <cms:show_repeatable> tag and using <cms:if fullname = "<cms:gpc 's'/>">.

This works perfectly but only when the search term is capitalised. E.g a search for Jimmy works but not jimmy. Is there a way to allow the <cms:if> tag to NOT be case sensitive. An alternative fix would be to make all search terms capitalised. Is there a way to do either of these fixes?

Thanks
wizardradio wrote: Hey KK,

I need to search repeatable regions. The work around I have used involves the use of the <cms:show_repeatable> tag and using <cms:if fullname = "<cms:gpc 's'/>">.

This works perfectly but only when the search term is capitalised. E.g a search for Jimmy works but not jimmy. Is there a way to allow the <cms:if> tag to NOT be case sensitive. An alternative fix would be to make all search terms capitalised. Is there a way to do either of these fixes?

Thanks


I'm not sure there's a native fix in Couch for this - you could make a regex requiring the first letter be capitalized as validation. My fix would be to do a Javascript manipulation of the form field and capitalize the value. Client-side normalization, something like this using jQuery:

Code: Select all
<cms:input type="text" name="search_field" id="search_field" />

<script>
    $('#search_field').change(function () {
        var tempValue = $('#search_field').val();
        var tempFront = tempValue.slice(0,1);
        var tempBack = tempValue.slice(1);
        tempValue = tempFront.toUpperCase() + tempBack.toLowerCase();
        $('#search_field').val(tempValue);
    });
</script>


KK probably has a native way to do it in Couch, as he's awesome, but that's how I solved a similar problem on my current project; clean it up clientside.
Hi,

The string comparison done by '=' operator (internally using PHP '==') is case-sensitive and that would explain why the values are not matching.

To solve it, let us try creating a quick-n-dirty tag (cms:str_cmp) that does a case-insensitive string comparison.

Please paste the following code verbatim in your 'couch/addons/kfunctions.php' file (create this file if not already present)
Code: Select all
function str_cmp( $params, $node ){
    if( count($node->children) ) {die("ERROR: Tag \"".$node->name."\" is a self closing tag");}
    if( count($params)<2 ) die( "ERROR: Tag \"".$node->name."\": requires two parameters" );
   
    $p0 = $params[0]['rhs'];
    $p1 = $params[1]['rhs'];
   
    $equal = ( strcasecmp($p0, $p1)==0 ) ? 1 : 0;
    return $equal;
}
$FUNCS->register_tag( 'str_cmp', 'str_cmp' );

Your code would now change from this -
Code: Select all
<cms:if fullname = "<cms:gpc 's'/>">
    ...
</cms:if>

to this -
Code: Select all
<cms:if "<cms:str_cmp fullname "<cms:gpc 's'/>" />" >
    ..
</cms:if>

Does this help?
Hey KK,

It works perfectly.

Thanks again for being so helpful :D
You are welcome :)
5 posts Page 1 of 1