Yii Framework Forum: Discussion and Questions on EJuiAutoCompleteFkField - Yii Framework Forum

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Discussion and Questions on EJuiAutoCompleteFkField Rate Topic: -----

#21 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 01 August 2011 - 08:57 PM

View Postjeremy, on 01 August 2011 - 07:23 AM, said:

use firebug to see what is happening. Make sure the ajax GET is happening after you type at least 2 characters in the autoComplete field. Examine the response from the server - maybe there's an error.


Hi Jeremy,

I checked the response from firebug, nothing is called there..... is there because of the indexing? what I suppose to do in a situation where the _formDetail is called by a javascript function?

I can manage to make it work on the other (normal) case.

Cheers,

Daniel
0

#22 User is offline   jeremy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 17-June 09
  • Location:Massachusetts, USA

Posted 01 August 2011 - 09:13 PM

If there's no ajax GET, then the js function is not attached properly. you're using renderPartial ( x, x, x, TRUE) which is correct. Have you ever used VisualEvent ? (http://www.sprymedia...le/Visual+Event) Install, then check a page where the autoCompleter is working properly. You should see the js event attached to the correct widget. In my working application, each EJuiAutoCompleteFkField widget has *6* events subscribed. Hover your cursor over each to see the js function for the event. Now, go to the non-working page. Use Visual Event again - are there any attached events?

View PostDaniel, on 01 August 2011 - 08:57 PM, said:

Hi Jeremy,

I checked the response from firebug, nothing is called there..... is there because of the indexing? what I suppose to do in a situation where the _formDetail is called by a javascript function?

I can manage to make it work on the other (normal) case.

Cheers,

Daniel

0

#23 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 01 August 2011 - 10:29 PM

View Postjeremy, on 01 August 2011 - 09:13 PM, said:

If there's no ajax GET, then the js function is not attached properly. you're using renderPartial ( x, x, x, TRUE) which is correct. Have you ever used VisualEvent ? (http://www.sprymedia...le/Visual+Event) Install, then check a page where the autoCompleter is working properly. You should see the js event attached to the correct widget. In my working application, each EJuiAutoCompleteFkField widget has *6* events subscribed. Hover your cursor over each to see the js function for the event. Now, go to the non-working page. Use Visual Event again - are there any attached events?


Hi, Jeremy,

Thanks for quick reply.

I installed Visual Event, and right on my working page, I saw 6 events. On my non working page, I can only see 1 event which is the onBlur.......I guess this is why it is not working. however, any hints to fix this? something related to the attributes?

Moreover, since I can add the new row from javascript, no new jquery autocomplete is genereated when arow is added. Any suggestion to this problem?

I remember that we should be able to attach a jquery script to a class not just an id, but no idea how could this be working in my situation......

Cheers,

Daniel
0

#24 User is offline   jeremy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 17-June 09
  • Location:Massachusetts, USA

Posted 02 August 2011 - 07:48 AM

the problem is with

'attribute' => '[$id]warehouseFk', 


the code is currently expecting the "attribute" to be a valid attribute of the model.

On the other hand, it's also using "[xx]warehouseFk" to match the element "id" and "name" generated by Yii; otherwise I'd suggest passing just "warehouseFk".

Please try modifying the extension as follows:
in init(), AFTER:
    	$this->_fieldName = get_class($this->model).'_'.$this->attribute;  // match what is generated by Yii
    	$this->_saveName = $this->attribute.'_save';
    	$this->_lookupName = $this->attribute.'_lookup';

add
// handle autoComplete rendered in child rows.  strip [xx] from the attribute to make it a valid attribute of $model
if (strpos($this->attribute, ']') {
   $parts = explode($this->attribute, ']');
   $this->attribute = $parts[1];
}


and see what happens. If it works I'll patch the extension and release a new version.

- Jeremy



View PostDaniel, on 01 August 2011 - 10:29 PM, said:

I installed Visual Event, and right on my working page, I saw 6 events. On my non working page, I can only see 1 event which is the onBlur.......I guess this is why it is not working. however, any hints to fix this? something related to the attributes?

Moreover, since I can add the new row from javascript, no new jquery autocomplete is genereated when arow is added. Any suggestion to this problem?

I remember that we should be able to attach a jquery script to a class not just an id, but no idea how could this be working in my situation......

0

#25 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 03 August 2011 - 05:50 PM

View Postjeremy, on 02 August 2011 - 07:48 AM, said:

the problem is with

'attribute' => '[$id]warehouseFk', 


the code is currently expecting the "attribute" to be a valid attribute of the model.

On the other hand, it's also using "[xx]warehouseFk" to match the element "id" and "name" generated by Yii; otherwise I'd suggest passing just "warehouseFk".

Please try modifying the extension as follows:
in init(), AFTER:
    	$this->_fieldName = get_class($this->model).'_'.$this->attribute;  // match what is generated by Yii
    	$this->_saveName = $this->attribute.'_save';
    	$this->_lookupName = $this->attribute.'_lookup';

add
// handle autoComplete rendered in child rows.  strip [xx] from the attribute to make it a valid attribute of $model
if (strpos($this->attribute, ']') {
   $parts = explode($this->attribute, ']');
   $this->attribute = $parts[1];
}


and see what happens. If it works I'll patch the extension and release a new version.

- Jeremy


Hi Jeremy,

I tried to add this part of code into your extension
if (strpos($this->attribute, ']')) {
   $parts = explode($this->attribute, ']');
   $this->attribute = $parts[1];
}


but still not working, it said no field "TransactionDetail." somehow it seems the $parts[1] is empty ;( I tried to print but could not see it anywhere, any idea to debug it?

Cheers,

Daniel
0

#26 User is offline   jeremy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 17-June 09
  • Location:Massachusetts, USA

Posted 03 August 2011 - 07:31 PM

OK - here is the fix:

1. when you create the widget, use double-quotes around the field-name
 'attribute' => "[$id]warehouseFk", 

otherwise it renders a literal "[$i]" instead of substituting the variable

2. remove the code I previously suggested

3. make this change in EJuiAutoCompleteFkField.init()
    	// JJD 8/3/11 make EJuiAutoCompleteFkField work for child rows where attribute like [$i]FieldName
    	//$this->_fieldName = get_class($this->model).'_'.$this->attribute;  // match what is generated by Yii
    	$this->_fieldName = CHtml::resolveName($this->model, $this->attribute); 


Let me know if it works for you. I tried in a view where I have child-rows, but the auto-completer was borrowed from another place in the app so I'm not 100% sure. But it did seem to work properly.

I'll release a new version with this patch if it works ok. Thanks for your patience.

- Jeremy

View PostDaniel, on 03 August 2011 - 05:50 PM, said:

Hi Jeremy,

I tried to add this part of code into your extension
if (strpos($this->attribute, ']')) {
   $parts = explode($this->attribute, ']');
   $this->attribute = $parts[1];
}


but still not working, it said no field "TransactionDetail." somehow it seems the $parts[1] is empty ;( I tried to print but could not see it anywhere, any idea to debug it?

Cheers,

Daniel

0

#27 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 03 August 2011 - 11:19 PM

Hi Jeremy,

I follow your instruction, it did work, however, only for the first row, next rows generated by javascript, would not display the autocomplete.

Other problem is when submitting, it is error.......it seemed not saving the fk .....

I attached my code, if you want to play with...

use warem / warem to login.

Thanks a lot for your support. Nice extension!

Cheers,

Daniel

Attached File(s)


0

#28 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 04 August 2011 - 09:52 PM

Hi Jeremy,

More info, your last fix will make the other page could not be submitted. It worked before, but becoming error on submit while I applied last fix.

Cheers,

Daniel
0

#29 User is offline   jeremy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 17-June 09
  • Location:Massachusetts, USA

Posted 04 August 2011 - 10:00 PM

Daniel,

See attached code. I *think* this version is working properly for [$i]fieldName, as well as for fieldName. If working, I'll publish the new version on the Extension homepage. Thanks for your patience. You're helping to improve the extension.

- Jeremy

Attached File(s)


0

#30 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 05 August 2011 - 07:24 AM

View Postjeremy, on 04 August 2011 - 10:00 PM, said:

Daniel,

See attached code. I *think* this version is working properly for [$i]fieldName, as well as for fieldName. If working, I'll publish the new version on the Extension homepage. Thanks for your patience. You're helping to improve the extension.

- Jeremy


Hi Jeremy,

Thanks a lot for your support. I tried on my code, and it works only for the first row. I wonder why it failed on the next row. Either, I generate from (+) button which is a javascript, or from the yii, prelaoded the create form with 3 details.

I don't know whether this info is useful, if I compare the textfield next to it is product, the id would be TransactionDetail_x_productFk while on your extension it is only TransactionDetail_warehouseFk. Since all id would be TransactionDetail_warehouseFk, it would be difficult to distinguish which one is belong to which id.

I am really thank you for your patience and kindly support to answer my questions.

Cheers,

Daniel
0

#31 User is offline   jeremy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 17-June 09
  • Location:Massachusetts, USA

Posted 05 August 2011 - 07:46 AM

Quote

I don't know whether this info is useful, if I compare the textfield next to it is product, the id would be TransactionDetail_x_productFk while on your extension it is only TransactionDetail_warehouseFk. Since all id would be TransactionDetail_warehouseFk, it would be difficult to distinguish which one is belong to which id.

Yes, the whole problem is getting the IDs to be correct, and unique.

Quote

Thanks a lot for your support. I tried on my code, and it works only for the first row. I wonder why it failed on the next row. Either, I generate from (+) button which is a javascript, or from the yii, prelaoded the create form with 3 details.

Are you sure it doesn't work for the existing rows? I have it working properly in my application for 20+ child rows, with valid autocompleters on each. But in my app, new rows cannot be created.

The problem with creating new rows is the autocompleter never gets attached to the field. This happens in anonymous js function that is executed after the page loads. Look at the very bottom of the HTML source and you'll see it., like this:
jQuery('#FIELDNAME').autocomplete({...


When you add a row using js, does it create another jQuery command like the one above? Please try and post the result here.
0

#32 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 05 August 2011 - 06:40 PM

Hi Jeremy,

The screenshot is attached.
Attached File  pic1.png (63.1K)
Number of downloads: 13


Here is my _formDDetail

<tr>    
    <td> 
        <?php
        $this->widget('EJuiAutoCompleteFkField', array(
            'model' => $model,
            'attribute' => "[$i]warehouseFk", //the FK field (from CJuiInputWidget)
            // controller method to return the autoComplete data (from CJuiAutoComplete)
            'sourceUrl' => Yii::app()->createUrl('/transaction/findWarehouse'),
            // defaults to false.  set 'true' to display the FK field with 'readonly' attribute.
//            'showFKField' => true,
            // display size of the FK field.  only matters if not hidden.  defaults to 10
//            'FKFieldSize' => 15,
            'relName' => 'warehouse', // the relation name defined above
            'displayAttr' => 'warehouseName', // attribute or pseudo-attribute to display
            // length of the AutoComplete/display field, defaults to 50
//            'autoCompleteLength' => 60,
            // any attributes of CJuiAutoComplete and jQuery JUI AutoComplete widget may 
            // also be defined.  read the code and docs for all options
            'options' => array(
                // number of characters that must be typed before 
                // autoCompleter returns a value, defaults to 2
//                'minLength' => 3,
            ),
        ));
        ?>
    </td>
    <td>
        <?php echo $form->textField($model, "[$id]productFk", array('style' => 'width: 250px;')); ?> 
    </td>
    <td> 
        <?php echo $form->textField($model, "[$id]batchNo", array('style' => 'width: 100px; text-align: center;')); ?>
    </td>
    <td> 
        <?php echo $form->textField($model, "[$id]quantity", array('style' => 'width: 100px; text-align: right;')); ?>
    </td>
    <td>
        <?php echo CHtml::link(CHtml::image(Yii::app()->request->baseUrl . '/images/remove_ico.png'), '', array('class' => 'delete', 'onClick' => 'deleteDetail($(this))')); ?>
    </td>
</tr>


and this is my controller that preloaded with 5 TransactionDetail

public function actionCreate() {
        $model = new Transaction;
        $model->date = date('Y-m-d');
        $model->status = Category::ACTIVE;
        $model->operatorFk = Yii::app()->user->id;

        $details = array();
        for ($i = 0; $i < 5; $i++) {
            $details[] = new TransactionDetail;
        }

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if (isset($_POST['Transaction'], $_POST['TransactionDetail'])) {
            $model->attributes = $_POST['Transaction'];
            $valid = $model->validate();

            $_POST['TransactionDetail'] = array_values($_POST['TransactionDetail']);

            $details = array();
            for ($i = 0; $i < count($_POST['TransactionDetail']); $i++) {
                $details[] = new TransactionDetail;
            }

            foreach ($details as $i => $detail) {
                if (isset($_POST['TransactionDetail'][$i]))
                    $detail->attributes = $_POST['TransactionDetail'][$i];
                $valid = $detail->validate() && $valid;
            }

            if ($valid) {
                $model->save();
                foreach ($details as $i => $detail) {
                    $detail->transactionFk = $model->id;
                    $detail->save();
                }
                $this->redirect(array('view', 'id' => $model->id));
            }
        }

        $this->render('create', array(
            'model' => $model,
            'details' => $details,
        ));
    }


Also, I was wondering why the button [x] is not displayed properly now?

Cheers,

Daniel
0

#33 User is offline   jeremy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 17-June 09
  • Location:Massachusetts, USA

Posted 09 August 2011 - 06:23 AM

Daniel,

It seems the problem is due to using renderPartial to show the existing and the new rows. My view does not use renderPartial(); each detail line is rendered as part of the parent form. But as I wrote before, in my case new rows are not allowed. I understand why you are using renderPartial(), this is correct for your situation.

Unfortunately I do not have time to make the extension work in this situation, right now. I am not sure it is possible to attach the jQuery autocomplete to an ajax response; but I haven't tried it yet. If you are able to improve it for your situation please post the code or send it to me; if it seems generally useful I'll incorporate back into the extension and republish.

The one thing I find puzzling about your last post is the Firebug screenshot, which shows the fieldname is -not- numbered. Even though you are using renderPartial the fieldNames should still get numbered properly. Are you definitely using the code I posted in this forum a few days ago?
0

#34 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 206
  • Joined: 26-September 09

Posted 11 August 2011 - 11:45 PM

View Postjeremy, on 09 August 2011 - 06:23 AM, said:

Daniel,

It seems the problem is due to using renderPartial to show the existing and the new rows. My view does not use renderPartial(); each detail line is rendered as part of the parent form. But as I wrote before, in my case new rows are not allowed. I understand why you are using renderPartial(), this is correct for your situation.

Unfortunately I do not have time to make the extension work in this situation, right now. I am not sure it is possible to attach the jQuery autocomplete to an ajax response; but I haven't tried it yet. If you are able to improve it for your situation please post the code or send it to me; if it seems generally useful I'll incorporate back into the extension and republish.

The one thing I find puzzling about your last post is the Firebug screenshot, which shows the fieldname is -not- numbered. Even though you are using renderPartial the fieldNames should still get numbered properly. Are you definitely using the code I posted in this forum a few days ago?


Hi Jeremy,

not sure yet how to do it. Someone mention about using .live, do you have any idea?

Cheers,

Daniel
0

#35 User is offline   Márcio Coragem 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 16-November 11

Posted 18 November 2011 - 07:37 AM

Hi

I'm using this extension in a app and it's working, but now i need to load two dependent dropdowns from a value selected in this field, using de fk id.

Anyone can tell me if its possible using this extension.
0

#36 User is offline   enfield 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 288
  • Joined: 12-January 11

Posted 13 March 2012 - 06:02 PM

Hi Jeremy,
First I wanted to say thanks for pulling this extension together, it is really helpful.

I have a problem that is confusing to the end users. If there is an error on any other value on the form that is not the EJuiAutoCompleteFkField, this field will then display the fk id and not the item that was in the auto complete drop down.

For example. I am using the field to select a city. So the user starts typing city names and the auto complete drop down works as it should and the user selects their city. But if they make an error anywhere else on the form the city field will now show the id (i.e. 456) instead of the city name they selected originally. I tried force setting this in an after find function but could not get that to work either. This is confusing to the end user so they go and try to type over that id with the city name again and only every once in awhile with the auto complete work without refreshing the whole page.

Any help with this?
0

#37 User is offline   crazzzyman 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 12-July 11

Posted 09 April 2012 - 01:19 AM

Hi Jeremy!
I have also problem as Márcio Coragem.
For example in first autocompleate field i choose city.
And in second autocompleate field i must to choose street in the city choosen in first field.
How i can to do it? (I mean second field with street).
0

#38 User is offline   btilley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 21-February 12

Posted 08 May 2012 - 09:54 AM

Great plugin, this has helped me out a lot.

Does anyone know how to specify the id or name of the FKfield (The hidden field that the FK is inserted into)?

Any help would be greatly appreciated.
0

#39 User is offline   btilley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 21-February 12

Posted 17 May 2012 - 01:32 PM

Any ideas why I would be getting the following error, when inserting a new row into my database:

Trying to get property of non-object

Here is call for the auto complete field:

$this->widget('EJuiAutoCompleteFkField', array(
				'model'=>$model_main,
				'attribute'=>'ordered_for_location_id', //the FK field (from CJuiInputWidget)
				// controller method to return the autoComplete data (from CJuiAutoComplete)
				'sourceUrl'=>Yii::app()->createUrl('ordersWls/FindLocations'),
				// defaults to false.  set 'true' to display the FK field with 'readonly' attribute.
				//'showFKField'=>true,
				// display size of the FK field.  only matters if not hidden.  defaults to 10
				'FKFieldSize'=>15,
				'relName'=>'ordersWlsDiscSusps', // the relation name defined above
				'displayAttr'=>'StreetCityAndState',  // attribute or pseudo-attribute to display
				// length of the AutoComplete/display field, defaults to 50
				'autoCompleteLength'=>80,
				// any attributes of CJuiAutoComplete and jQuery JUI AutoComplete widget may 
				// also be defined.  read the code and docs for all options
				'options'=>array(
					  // number of characters that must be typed before 
					  // autoCompleter returns a value, defaults to 2
					  'minLength'=>3,					  
				),
		));

0

#40 User is offline   btilley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 21-February 12

Posted 17 May 2012 - 02:29 PM

My mistake, I called to an incorrect relation. Issue solved by using the correct relation.
0

Share this topic:


  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users