How to add new fields in the asset edit page

thread: 4 messages  |  last: about 5 years ago  |  started: friday, august 9, 2013, 10:41 am pdt


#1  |  mervinthomas (chennai) India
Friday, August 9, 2013, 10:41 AM PDT

Hi,
I would like to add custom fields in the asset edit page for the users to enter values, I called the $this->customFields_create() in the consturctor and defined the method as follows in the file QAssetTransactComposite.class.php

   protected function customFields_Create(){
       $customFields  = CustomField::LoadObjCustomFieldArray(1, false);
       foreach ( $customFields as $customField ){
           if($customField->BatchEditableFlag == 1 ){
               $fieldType  = CustomFieldQtype::ToString( $customField->CustomFieldQtypeId );
               
               switch( $fieldType ):
                   case 'text':
                       $newField = new QTextBox($this);
                   break;
                   case 'select':
                       $newField = new QListBox($this);
                   break;
                   case 'textarea':
                       $newField = new QTextBox($this);
                       $newField->TextMode = QTextMode::MultiLine;
                       $newField->Columns = 80;
                       $newField->Rows = 4;
                       
                   break;
               endswitch;

               $newField->Name  = $customField->ShortDescription;
               // echo $newField->Name  . “<br />”;
               $this->customFields[] = $newField;
           }
       }
       // print_r( $this->customFields );
   }


but the custom fields is not rendering to the output. could you please anyone help me ?

#2  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Friday, August 9, 2013, 1:36 PM PDT

Hello mervinthomas,

where and how called the Render() or RenderWithName() or RenderWithError() function?

Regards,
 Attila

#3  |  mervinthomas (chennai) India
Saturday, August 10, 2013, 11:21 PM PDT

Hi gasper,
Thanks for your reply

I called the render in the tpl file ( asset_edit_tpl.php ) as follows

<?php $this->ctlAssetTransact->Render(); ?>

and in asset_edit.php the code is for create

       // Create the AssetTransact Composite control
       protected function ctlAssetTransact_Create() {
           $this->ctlAssetTransact = new QAssetTransactComposite($this);
       }

please let me know if you need anything else ?

#4  |  Gaspar Attila (Odorheiu Secuiesc, RO) Romania
Thursday, August 15, 2013, 4:23 AM PDT

Hi,

okay, but my question is related to custom fields controls.

When you call the customFields_Create() function the $this->customFields[] array filled the existing custom fileds but not rendered. You need to call the Render function one by one, or set their parent object AutoRenderChildren property to true.

I recommend to make a foreach in the tpl file and call the render function on every item.
This way you can make a template (html) to the custom field.



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