QQuery with Ajax?

thread: 4 messages  |  last: about 9 years ago  |  started: tuesday, september 8, 2009, 10:33 pm pdt


#1  |  Eestlane Estonia
Tuesday, September 8, 2009, 10:33 PM PDT
<?php


    
require('includes/prepend.inc.php');
    

    class 
SampleForm extends QForm
    
{

        protected 
$name;
        protected 
$btnButton;


        protected function 
Form_Create() 
        {

            
$this->name = new QLabel($this);
            
$this->name->Text 'John';

            
$this->btnButton = new QButton($this);
            
$this->btnButton->Text 'Add name';

            
$this->btnButton->AddAction(new QClickEvent(), new QAjaxAction('btnButton_Click'));


        } 
// End of 
        
        

        
protected function btnButton_Click ($strFormId$strControlId$strParameter
        {    
            
/*
                $objPerson = new Person();
                $objPerson->FirstName = $this->name->Text;
                $objPerson->Save();
                
                   $objPersonArray1 = Person::QueryArray
                (
                    QQ::Like(QQN::Person()->FirstName, $objPerson->FirstName) //
                );
    
            */
            
        
// End of btnButton_Click


    
// End of SampleForm

    
SampleForm::Run('SampleForm');
    
?>

Didn`t find any excamples on how can I extend this SampleForm with QQuery and how can I use QQuery with QAjaxAction. Does anyone know some excamples that may help to get solution?

#2  |  Vass Arpad (Szentegyháza, RO) Romania Qcodo Core Contributor
Wednesday, September 9, 2009, 12:19 AM PDT

Hi,

QQueries are the same don't matter that you use QServerAction or QAjaxAction.

The query is performed, and the QControl changes are applied.
And a working example is right here in the SampleForm posted by you, the commented part.

here is another example, which counts the persons having 'John' as FirstName, following your example.

<?php 
..........
protected 
$lblPersonCount;
..........

protected function 
Form_Create() 
        {

            
$this->name = new QLabel($this);
            
$this->name->Text 'John';

            
$this->lblPersonCount = new QLabel($this);
            
$this->lblPersonCount->Text '0';
...........
        protected function 
btnButton_Click ($strFormId$strControlId$strParameter
        {    
            
$cntPersons Person::QueryCount(
                
QQ::Like(QQN::Person()->FirstName$objPerson->FirstName)
            );

            
$this->lblPersonCount->Text $cntPersons;

            
/*
                $objPerson = new Person();
                $objPerson->FirstName = $this->name->Text;
                $objPerson->Save();
                
                   $objPersonArray1 = Person::QueryArray
                (
                    QQ::Like(QQN::Person()->FirstName, $objPerson->FirstName) //
                );
    
            */
            
        
// End of btnButton_Click
?>

hope this helps,

regards,

Arpi.

#3  |  Eestlane Estonia
Wednesday, September 9, 2009, 1:16 AM PDT
<?php


    
require('includes/prepend.inc.php');
    

    class 
SampleForm extends QForm
    
{

        protected 
$name;
        protected 
$btnButton;


        protected function 
Form_Create() 
        {

            
$this->name = new QLabel($this);
            
$this->name->Text 'John';

            
$this->btnButton = new QButton($this);
            
$this->btnButton->Text 'Add name';

            
$this->btnButton->AddAction(new QClickEvent(), new QAjaxAction('btnButton_Click'));


        } 
// End of 
        
        

        
protected function btnButton_Click ($strFormId$strControlId$strParameter
        {    

                
$objPerson = new Person();
                
$objPerson->FirstName $this->name->Text;
                
$objPerson->Save();
                
                   
$objPersonArray1 Person::QueryArray
                
(
                    
QQ::Like(QQN::Person()->FirstName$objPerson->FirstName//
                
);
    
            
        } 
// End of btnButton_Click


    
// End of SampleForm

    
SampleForm::Run('SampleForm');
    
?>

Thanks!

Tried again and now it worked... Strange but maybe when I tried earlier, I had some simple problem and got the following error:

http://localhost/

An error occureed during AJAX Responce parsing.

The error responce will appear in a new popup.

And when this type of error panel is displayed and OK is pressed, nothing happens (have tried with 2 different browsers and there was also no sign of pop-up blocking).

#4  |  Vass Arpad (Szentegyháza, RO) Romania Qcodo Core Contributor
Wednesday, September 9, 2009, 3:58 AM PDT

Yes... it's tricky.

it often happens with me, that an earlier popup windows remain unclosed, and after that the error doesn't appears, just a white content in the unclosed pop-up window.

regards,
Arpi.



Copyright © 2005 - 2019, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.