Autocomplete field shows twice in the translation form

A place for users and developers of the Xataface to discuss and receive support.

Autocomplete field shows twice in the translation form

Postby the_woz » Mon Mar 12, 2012 10:55 pm

I noticed a couple of problems today in the translation form, the first was the preview for the logo field was missing, and the "View field in New Window" link pointed to an URL of this type:

http://www.mysite.com/http://www.mysite ... gofile.gif

I traced the problem to the default template file "Dataface_TranslationForm_element.html"

and changed this:

Code: Select all
   {if $properties.image_preview}
   <img src="{$smarty.server.HOST_URI}{$properties.image_preview}" style="display: block; max-height: 200px" alt="{$field.name} preview image"/>
   {/if}
   {if $properties.preview}
   <a href="{$smarty.server.HOST_URI}{$properties.preview}" target="_blank">{translate id="scripts.GLOBAL.MESSAGE_VIEW_FIELD_CONTENT"}View Field Content in new Window{/translate}</a>
   {/if}


to this (made a copy on my theme directory instead of changing the original file):

Code: Select all
   {if $properties.image_preview}
   <img src="{$properties.image_preview}" style="display: block; max-height: 200px" alt="{$field.name} preview image"/>
   {/if}
   {if $properties.preview}
   <a href="{$properties.preview}" target="_blank">{translate id="scripts.GLOBAL.MESSAGE_VIEW_FIELD_CONTENT"}View Field Content in new Window{/translate}</a>
   {/if}


Now the logo field preview shows correctly.

The second problem, and the cause of this post is a very strange one, field with a autocomplete widget type display twice in the translation form, it happens only with this widget type, yui_autocomplete displays correctly.

Here's a screenshot:
Image

The country field is set as yui_autocomplete while Language is set as autocomplete and is shown twice.

I was using Xataface 1.3rc6 when I found this, I updated to 1.3.2 but nothing changed.
the_woz
 
Posts: 12
Joined: Fri Sep 16, 2011 11:37 am

Re: Autocomplete field shows twice in the translation form

Postby the_woz » Wed Mar 14, 2012 5:44 pm

Any idea about what can be causing this?

I traced the problem to DatafaceTranslationForm::display(), the duplicate field appears after a call to $this->_build() (line 248 of /Dataface/TranslationForm.php).

function display(){
if ( $this->_resultSet->found()>0 || $this->_new ){
$res = $this->_build(); //<<<<<-----echoing the fieldnames from inside Dataface_Quickform::_build() here shows each field only once, as it should be
if ( PEAR::isError($res) ){
return $res;
}
else {
//$this->displayTabs();
if ( !$this->_new and !Dataface_PermissionsTool::edit($this->_record) ){
$this->freeze();
}

if ( $this->_new and /*!Dataface_PermissionsTool::edit($this->_table)*/!Dataface_PermissionsTool::checkPermission('new',$this->_table) ){
$this->freeze();
}
$this->accept($this->_renderer); //<<<<<-----echoing the fieldnames from inside HTML_Quickform::accept(&$renderer) here shows the autocomplete field already duplicated
//$formTool =& Dataface_FormTool::getInstance();


if ( $this->_new || Dataface_PermissionsTool::view($this->_record) ){
echo $this->_renderer->toHtml();
//echo $formTool->display($this);
} else {
echo "<p>".df_translate('scripts.GLOBAL.INSUFFICIENT_PERMISSIONS_TO_VIEW_RECORD','Sorry you have insufficient permissions to view this record.')."</p>";
}
//parent::display();
}
} else {
echo "<p>".df_translate('scripts.GLOBAL.NO_RECORDS_MATCHED_REQUEST','No records matched your request.')."</p>";
}
}


I tried uncommenting line 507 of /Dataface/QuickForm.php (inside the _build() method)

Code: Select all
            //$this->addElement($el);


And as I suspected it resulted in all the fields being duplicated, but instead of getting 4 copies of the autocomplete field, there was only 3.

This is as far (or near the problem) as I could get, any help or hit on how to fix this problem will be very appreciated.
the_woz
 
Posts: 12
Joined: Fri Sep 16, 2011 11:37 am

Re: Autocomplete field shows twice in the translation form

Postby the_woz » Fri Mar 16, 2012 3:00 pm

I finally managed to trace the bug to /Dataface/FormTool/autocomplete.php

Code: Select all
<?php

class Dataface_FormTool_autocomplete {
   function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
      $widget =& $field['widget'];
      $options =& Dataface_FormTool::getVocabulary($record, $field);
      $el =& $form->addElement('autocomplete', $formFieldName, $widget['label'], array('class'=>$widget['class'], 'id'=>$field['name']) );
      $el->setOptions($options);
      return $el;
   }
}


When building the form (any form, not just the translation form), this function is called twice per widget from different places.
The element must be added to the form only once, near the end of FormTool::buildWidget(), but here in autocomplete.php it's added each time is called; resulting in duplicated fields.

To fix this problem, I made the following modifications after checking the buildWidget functions of other widget types:

Code: Select all
<?php

class Dataface_FormTool_autocomplete {
   function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
      $widget =& $field['widget'];
      $options =& Dataface_FormTool::getVocabulary($record, $field);
      $factory =& Dataface_FormTool::factory();
      $el =& $factory->addElement('autocomplete', $formFieldName, $widget['label'], array('class'=>$widget['class'], 'id'=>$field['name']) );
      $el->setOptions($options);
      return $el;
   }
}



Now the autocomplete widgets shows only once in the translation form, and still works fine in the edit form.
the_woz
 
Posts: 12
Joined: Fri Sep 16, 2011 11:37 am

Re: Autocomplete field shows twice in the translation form

Postby shannah » Fri Mar 16, 2012 3:15 pm

Thanks for the patch. I've added this change to SVN.

1.3.x branch rev 3423
1.5.x branch rev 3424
trunk rev 3422

It will be included in all future releases.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Autocomplete field shows twice in the translation form

Postby the_woz » Sat Mar 17, 2012 9:50 am

You're welcome :)

I'm glad to be of help in the development of this great framework.
the_woz
 
Posts: 12
Joined: Fri Sep 16, 2011 11:37 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 4 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved