⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

How to custom field on form view



Ana Letícia
  • profile picture
  • Member

Posted 29 April 2014 - 18:08 PM

Hi Everyone, I hope  you  understand me

 

So  I  have  a table about News and I change a column "publicate"(enum : y/n) with display_as "Status"(enum: Yes/No). It works on add form  and  edit form,  but  on view form it is showing "Status"(enum:y/n).  I've tried to use callback_field,callback_column and doesn't work. Someone can help me?

 

Here is my code:

 

$crud->set_table('ibdfam_noticias')
            ->set_subject('Notícias do IBDFAM')
            ->columns('titulo','publicar','destaque','fonte')
            ->display_as('publicar', 'Status')
            ->display_as('hora', 'Data')
            ->fields('titulo','texto','publicar','tags','hora','fonte','destaque','image','creditos','tipo')
            ->field_type('publicar','dropdown',array('s' => 'Ativo', 'n' => 'Inativo'))
            ->field_type('destaque','dropdown',array(0 => 'Não', 1 => 'Sim'))
            ->callback_column('publicar',array($this,'_status'));

 

    public function _status($value, $row)
    {
        
        if($value == 's'){
            $value = 'Ativo';
         }elseif($value =='n'){
            $value =  'Inativo';
         }
        return $value;
    }


Amit Shah
  • profile picture
  • Member

Posted 29 April 2014 - 22:27 PM

well there is a function callback_read_field in the gc library - not documented-  u can use that


Ana Letícia
  • profile picture
  • Member

Posted 30 April 2014 - 17:55 PM

Amit,  I didn't  find   this function callback_read_field . Can you be more clear  about  how  to use it?


Amit Shah
  • profile picture
  • Member

Posted 01 May 2014 - 06:28 AM

this function is available with gc 1.4.1 - believe - check it if you have it.. else i will share you the version of library i have (i have modified it.. with quite a lot of other functionalities to my requirements).


Ana Letícia
  • profile picture
  • Member

Posted 02 May 2014 - 16:40 PM

My  version is 1.4.1 but  it  doesn't work,  do you have it in github? or send  to my  email  ana.leticia.cn@hotmail.com


edramirez
  • profile picture
  • Member

Posted 03 June 2014 - 16:50 PM

Hi, Ana -

 

"Calculated values" work correctly in the add and edit modes but don't appear correctly in the view section. This is not limited to your example. Oftentimes I am faced with the question on whether to figure out a solution or eliminate the view section altogether. In my personal experience, I have found it more beneficial to remove the view section and not bother with any additional programming to correct the problem.

 

There are two kinds of geniuses - the first deals with the ability to solve problems and the second deals with eliminating the need to solve a problem. As a developer, you sometimes need to be on or the other. So, don't forget to click the Like button...

 

Regards,

 

Ed Ramirez


Amit Shah
  • profile picture
  • Member

Posted 04 June 2014 - 13:22 PM

hi ana

 

refer to the following url - its same issue.. patch coe given in there!!

/topic/2525-callback-addedit-field-changes-the-display-on-the-read-method/