Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Conditionals in bind expression

LEGEND ,
Apr 27, 2011 Apr 27, 2011

Is it possible to put a conditional in a bind expression?

For example:

<cfinput type="text" name="searchParam" id="searchParam">

<cfdiv id="searchResult" bindonload="no" bind="url:sr.cfm?search_param={searchParam@blur}"></cfdiv>

In this example, sr.cfm will be loaded in the cfdiv EVERY TIME that focus is blurred from the input field.

Is it possible to set it so that the cfdiv will NOT load sr.cfm IF the input field is blank??  Something like:

bind="url:sr.cfm?search_param={searchParam<cfif searchParam neq ''>@blur</cfif>}"

Is this possible?  Or is there something like it that will work?

Thanks,

^_^

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2011 Apr 28, 2011

Put your conditional logic into sr.cfm.  If there is no searchparam, return an empty page.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2011 Apr 28, 2011

Dan Bracuk wrote:

Put your conditional logic into sr.cfm.  If there is no searchparam, return an empty page.

I'd like to prevent the cfdiv from loading in the first place (if the field is blank), if at all possible.  The field gets focus on initial page load, and I'd like to have it not load anything in the cfdiv if a link is clicked, first.  Currently, the cfdiv loads if a link is clicked, first, due to the @blur.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2011 Apr 28, 2011

WolfShade wrote:

Dan Bracuk wrote:

Put your conditional logic into sr.cfm.  If there is no searchparam, return an empty page.

I'd like to prevent the cfdiv from loading in the first place (if the field is blank), if at all possible.  The field gets focus on initial page load, and I'd like to have it not load anything in the cfdiv if a link is clicked, first.  Currently, the cfdiv loads if a link is clicked, first, due to the @blur.

^_^

Is it possible?  Can conditionals be used between { and } ?

Thanks,

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 28, 2011 Apr 28, 2011

If you do try conditional logic, make sure it's js and not cf.

As far as having the div being blank when the page loads, it should be.  If it's not, try to find the action that is causing it to be loaded.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 02, 2011 May 02, 2011

The cfdiv IS blank when the page first loads.  And focus is placed on the text field when the page first loads.

If a search is immediately entered, no problem.

If a link is clicked immediately after the page load, then there's a problem.  On blur, the cfdiv loads based on the search parameter, which is blank, so it's trying to get everything.  I'd like to try to keep the cfdiv from loading if the search field is blank when the blur happens.

^_^

PS.  I should say that I tried to set the search up so that it would start onKeyPress, onKeyUp, and onKeyDown (not all at the same time); but that caused a HUGE issue in IE7 (the browser that the company is forcing employees to use) if it worked, at all (only onKeyUp actually worked - onKeyDown and onKeyPress didn't include the currently entered letter.)  It would cause IE7 to bog down horribly - it would take anywhere from 15 to 60 seconds to complete the process that FF would do in a few seconds.  Well, I'm testing on FF just because (because I like FF's Error Console!), but very few people in this company have that option.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2011 May 03, 2011

I didn't see anything in CF9 support on adobe.com about conditionals in the bind, but I don't want to just assume that it can't be done.

Has anyone successfully written a conditional within a bind expression?

Thanks,

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2011 May 03, 2011

Regarding

On blur, the cfdiv loads based on the search parameter, which is blank, so it's trying to get everything.  I'd like to try to keep the cfdiv from loading if the search field is blank when the blur happens.

Why don't you just have the cfc to return nothing instead of everything when there is no search parameter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 03, 2011 May 03, 2011

The CFDIV loading is attached to the blur of the search field, regardless of whether there are 10 records, 1000 records, or 0 records.

I suggested that they change the bind from @blur to @change, but they don't like that suggestion.  They want records to start appearing with each keystroke (each keystroke calls a function that blurs the field then refocuses the field, triggering the bind.)

I just want it so that if nothing is typed but the field is blurred, it won't load the CFDIV.

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 05, 2011 May 05, 2011
LATEST

Another site helped me figure it out.

<cfajaxproxy bind="javascript:searchOnBlur({search_text@blur},{search_type@blur},'search_text','comp')">

<script type="text/javascript">

searchOnBlur = function(a,z,b,c) {
    sf = document.app_search;
    cc = document.app_search;
    st = "";
    for(i=0;i<document.app_search.search_type.length;i++) {
        document.app_search.search_type.checked ? st = document.app_search.search_type.value : null ;
        }
    if(cc.value != sf.value) {
        cc.value = sf.value;
        ColdFusion.navigate("search_results.cfm?search_text="+sf.value+"&search_type="+st+"",'search_results',mycallBack,myerrorHandler);
        }
    }

</script>

<cfinput type="text" name="search_text" id="search_text">

<cfinput type="hidden" name="comp" id="comp" value="">

search_type=radio inputs (two of them); one for name, the other for number

^_^

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources