..:: MX Studio Fóruns ::..: Dúvidas em uma aplicação igual ao Google suggest - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




ATENÇÃO

Para evitar posts desnecessários e que não influam para o andamento e desenvolvimento do fórum, clique aqui e leia todas as regras.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dúvidas em uma aplicação igual ao Google suggest Tutorial passo a passo

#1 User is offline   Dsouza 

  • Group: Colunistas
  • Posts: 138
  • Joined: 16-September 05

Posted 28 March 2006 - 02:52 PM

Segue o tutorial:
QUOTE
CFAJAX Suggest
« H » email link
CFAJAX 1.2.1 adds a feature called "suggest," a type of autocomplete similar to the email address completion in Google's GMail. Based on the return from a CFAJAX driven CF function, values matching the initial entry into a textbox are shown, so the user can pick from a list rather than typing the whole thing.

(UPDATE: The steps below now include a very simple cf function to return a query to the JS, to ensure people know it really is quite straightforward).

To use the suggest feature, the following are necessary as a minimum:

1) Include the relevant CFAJAX JS scripts in the html (use your own paths as appropriate) e.g.



<script type='text/javascript' src='/cfajax.1.2.1/core/prototype.js'></script>
<script type='text/javascript' src='/cfajax.1.2.1/core/suggest.js'></script>
<script type='text/javascript' src='/cfajax.1.2.1/core/engine.js'></script>
<script type='text/javascript' src='/cfajax.1.2.1/core/util.js'></script>
<script type='text/javascript' src='/cfajax.1.2.1/core/settings.js'></script>



2) Create the suggest object before anything tries to use it (i.e. in the head of the page) and initialise a variable to pass as a search string:



<script language='javascript'>
  var mySuggestObject= new Suggest();
  var searchString = "";
</script>


3) Create a function to run at the body onload event to initialise the suggest object with the form field that is going to use it:



<script language='javascript'>



  function onInit()
            {
                onSuggestFieldFocus(mySuggestObject);
                mySuggestObject.InitQueryCode('mySuggestObject','formfieldname')
            }
</script>



4) Create a function called getData() that will do the CFAJAX call (the name of this fucntion is important as it's how the suggest object knows what to do) and a return handler



function getData(qry)
            {
                searchString = qry;
                DWREngine._execute(_cfscriptLocation, null, 'myCFFuction', searchString, getDataResult);
            }

function getDataResult(return)
            /*
            this function assumes a CF query object with columns USERNAME and DN is coming back from the database via the CF function
            as the username is typed, the full DN is displayed as the suggest option
            */
            { var key = Array();
                var value = Array();
               
                for (i=0; i < return.length; i++)
                {
                    key[i] = return[i].USERNAME; //if your query has a different column name, use it here
                    value[i] = return[i].DN;  //if your query has a different column name, use it here
                }
                strQuery = selectedSuggestObject.name + '.showQueryDiv("' + searchString + '", key , value)';
                eval (strQuery);
            }



5) In the form, the form element needs to call the onSuggestFieldFocus() function e.g.:

<input id="formfieldname" name="formfieldname" value="" size=20 autocomplete="off" onFocus="onSuggestFieldFocus(mySuggestObject)">

6) Make sure the CF function in your functions.cfm file returns a query, for example:

<cffunction name="myCFFuction" returntype="query" output="no">
  <cfargument name="searchString" type="string" required="yes">
  <cfset var QGetMatchingUsers="">
  <cfquery name="QGetMatchingUsers" datasource="myDSN">
    SELECT username,dn
        FROM users
    WHERE username LIKE <cfqueryparam cfslqtype="cf_sql_varchar" value="#ARGUMENTS.searchString#%">
  </cfquery>
  <cfreturn QGetMatchingUsers>
<cffunction>


Página com os arquivos:
http://www.indiankey.com/cfajax/project.asp

Exemplo ao vivo!
http://www.indiankey.com/cfajax/examples/suggest.htm

Alguem consegui fazer ??????????
Abraços !
0

#2 User is offline   Dsouza 

  • Group: Colunistas
  • Posts: 138
  • Joined: 16-September 05

Posted 29 March 2006 - 01:36 PM

Galera , já consegui fazer!

Ficou show de bola.

Muito mais rápido e bonito do que esse ai do CFAJAX
0

#3 User is offline   alexmaia 

  • Group: Membros
  • Posts: 246
  • Joined: 04-February 05

Posted 27 April 2006 - 04:46 PM

Tambem nao consegui fazer esse nao...

Voce pode dizer onde encontrou esse exemplo melhor ? Em que site ? smile.gif

Valeu
0

#4 User is offline   Dsouza 

  • Group: Colunistas
  • Posts: 138
  • Joined: 16-September 05

Posted 30 April 2006 - 11:19 AM

Cara foi no easycfm, é do Claudio Dias, ele é muito bom!


É batata

http://tutorial364.easycfm.com/

a resposta é muito mais rápida do que a desses sites.
0

#5 User is offline   alexmaia 

  • Group: Membros
  • Posts: 246
  • Joined: 04-February 05

Posted 03 May 2006 - 03:03 PM

Opa!
Valeu cara... O exemplo realmente é bem interessante!

Vou tentar alterar ele para que funcione buscando os registros direto do banco..

Valeu
0

#6 User is offline   Dsouza 

  • Group: Colunistas
  • Posts: 138
  • Joined: 16-September 05

Posted 04 May 2006 - 12:25 PM

Grande Alex,



Saca para que ele busque direto do banco basta alterar o countries.cfm desta maneira.


Countries.cfm
ColdFusion

<cfapplication name="suggestList" sessionmanagement="Yes">

<cfquery datasource="#DSN#" name="qSearch">
SELECT P_NAME
FROM categoria
WHERE upper(P_NAME) LIKE '%#uCase(URL.search)#%'
ORDER BY P_NAME
</cfquery>
<cfsetting enablecfoutputonly="Yes">
<cfoutput>#valueList(qSearch.P_NAME)#</cfoutput>



Consome menos recursos de memória.

grande abraço.
0

#7 User is offline   alexmaia 

  • Group: Membros
  • Posts: 246
  • Joined: 04-February 05

Posted 04 May 2006 - 03:31 PM

Perfeito Dsouza. Exatamente isso.

E para impedir que o usuario acesse a pagina countries.cfm direto do browser e veja erro de sintaxe que é gerado
CODE
Element SEARCH is undefined in URL.

poderiamos colocar um CFIF no inicio dela averiguando se a variavel URL.search esta ou nao definida... Se tiver, faz a consulta... Se nao tiver, vai pra form.htm smile.gif

Valeu

0

#8 User is offline   Dsouza 

  • Group: Colunistas
  • Posts: 138
  • Joined: 16-September 05

Posted 06 May 2006 - 02:44 PM

Boa ideia brooo!

Valeu!!
0

#9 User is offline   CRSramone 

  • Group: Membros
  • Posts: 88
  • Joined: 12-July 05

Posted 23 May 2007 - 01:46 PM

Desculpem voltar nesse tópico, mas eu não estou conseguindo fazer o tutorial do EasyCFM funcionar....

Sou meio ruim com JavaScript, e acho que é nele o problema.

Se alguem tiver isso pronto para testar vai ser muito bom...

Obrigado.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


Similar Topics Collapse

  Topic Forum Started By Stats Last Post Info
New Replies Google testa carro sem motorista nas ruas da Califórnia Notícias Notícias 
  • 0 Replies
  • 90 Views
New Replies Galeria de Imagens
Preciso criar uma galeria de imagens com este rescurso
Biblioteca de Scripts agviana 
  • 2 Replies
  • 1899 Views
New Replies Google reforça publicidade local com logotipos
Terra Tecnologia
Notícias TiTi Celestino 
  • 0 Replies
  • 382 Views
New Replies google maps
ache sua casa.
Outros Only Dust 
  • 0 Replies
  • 1438 Views
New Replies Tiro dúvidas e dou códigos e macetes
Debates entre códigos e macetes para fechar jogos
Jogos Só Need 
  • 7 Replies
  • 4910 Views
New Replies carregar
uma pagina feita no flash
Flash & ActionScript luizofgod 
  • 2 Replies
  • 620 Views
New Replies Como criar uma galeria de fotos, com BD Dreamweaver vpess 
  • 3 Replies
  • 1702 Views
New Replies Desenhando a caricatura de um Coelho
Aprenda em alguns passos como fazer um Coelho de Páscoa desde o zero
Photoshop & Image Ready CrazyBR 
  • 1 Reply
  • 3993 Views

Publicidade




1 User(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)